Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
nheko
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nheko Reborn
nheko
Commits
beec2607
Commit
beec2607
authored
4 years ago
by
Jussi Kuokkanen
Browse files
Options
Downloads
Patches
Plain Diff
get completion string based on trigger position instead of current word
parent
254b7549
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/TextInputWidget.cpp
+9
-8
9 additions, 8 deletions
src/TextInputWidget.cpp
src/TextInputWidget.h
+10
-2
10 additions, 2 deletions
src/TextInputWidget.h
with
19 additions
and
10 deletions
src/TextInputWidget.cpp
+
9
−
8
View file @
beec2607
...
...
@@ -129,10 +129,10 @@ void
FilteredTextEdit
::
insertCompletion
(
QString
completion
)
{
// Paint the current word and replace it with 'completion'
auto
cur_
word
=
wordUnderCursor
(
);
auto
cur_
text
=
textAfterPosition
(
trigger_pos_
);
auto
tc
=
textCursor
();
tc
.
movePosition
(
QTextCursor
::
Left
,
QTextCursor
::
MoveAnchor
,
cur_
word
.
length
());
tc
.
movePosition
(
QTextCursor
::
Right
,
QTextCursor
::
KeepAnchor
,
cur_
word
.
length
());
tc
.
movePosition
(
QTextCursor
::
Left
,
QTextCursor
::
MoveAnchor
,
cur_
text
.
length
());
tc
.
movePosition
(
QTextCursor
::
Right
,
QTextCursor
::
KeepAnchor
,
cur_
text
.
length
());
tc
.
insertText
(
completion
);
setTextCursor
(
tc
);
}
...
...
@@ -248,8 +248,8 @@ FilteredTextEdit::keyPressEvent(QKeyEvent *event)
}
case
Qt
::
Key_Colon
:
{
QTextEdit
::
keyPressEvent
(
event
);
trigger_pos_
=
textCursor
().
position
()
-
1
;
emoji_popup_open_
=
true
;
emoji_completion_model_
->
setFilterRegExp
(
wordUnderCursor
());
break
;
}
case
Qt
::
Key_Return
:
...
...
@@ -311,15 +311,15 @@ FilteredTextEdit::keyPressEvent(QKeyEvent *event)
if
(
isModifier
)
return
;
if
(
emoji_popup_open_
&&
wordUnderCursor
(
).
length
()
>
2
)
{
if
(
emoji_popup_open_
&&
textAfterPosition
(
trigger_pos_
).
length
()
>
2
)
{
// Update completion
emoji_completion_model_
->
setFilterRegExp
(
wordUnderCursor
(
));
emoji_completion_model_
->
setFilterRegExp
(
textAfterPosition
(
trigger_pos_
));
completer_
->
complete
(
completerRect
());
}
if
(
emoji_popup_open_
&&
(
completer_
->
completionCount
()
<
1
||
!
wordUnderCursor
(
).
contains
(
QRegExp
(
":[^
\r\n\t\f\v
:]+$"
))))
{
!
textAfterPosition
(
trigger_pos_
).
contains
(
QRegExp
(
":[^
\r\n\t\f\v
:]+$"
))))
{
// No completions for this word or another word than the completer was
// started with
emoji_popup_open_
=
false
;
...
...
@@ -441,7 +441,8 @@ FilteredTextEdit::completerRect()
// Move left edge to the beginning of the word
auto
cursor
=
textCursor
();
auto
rect
=
cursorRect
();
cursor
.
movePosition
(
QTextCursor
::
Left
,
QTextCursor
::
MoveAnchor
,
wordUnderCursor
().
length
());
cursor
.
movePosition
(
QTextCursor
::
Left
,
QTextCursor
::
MoveAnchor
,
textAfterPosition
(
trigger_pos_
).
length
());
auto
cursor_global_x
=
viewport
()
->
mapToGlobal
(
cursorRect
(
cursor
).
topLeft
()).
x
();
auto
rect_global_left
=
viewport
()
->
mapToGlobal
(
rect
.
bottomLeft
()).
x
();
auto
dx
=
qAbs
(
rect_global_left
-
cursor_global_x
);
...
...
This diff is collapsed.
Click to expand it.
src/TextInputWidget.h
+
10
−
2
View file @
beec2607
...
...
@@ -86,6 +86,7 @@ private:
bool
emoji_popup_open_
=
false
;
CompletionModel
*
emoji_completion_model_
;
std
::
deque
<
QString
>
true_history_
,
working_history_
;
int
trigger_pos_
;
// Where emoji completer was triggered
size_t
history_index_
;
QCompleter
*
completer_
;
QTimer
*
typingTimer_
;
...
...
@@ -116,7 +117,14 @@ private:
cursor
.
movePosition
(
QTextCursor
::
StartOfWord
,
QTextCursor
::
KeepAnchor
);
return
cursor
.
selectedText
();
}
QString
wordUnderCursor
()
QString
textAfterPosition
(
int
pos
)
{
auto
tc
=
textCursor
();
tc
.
setPosition
(
pos
);
tc
.
movePosition
(
QTextCursor
::
EndOfBlock
,
QTextCursor
::
KeepAnchor
);
return
tc
.
selectedText
();
}
/*QString wordUnderCursor()
{
auto tc = textCursor();
auto editor_text = toPlainText();
...
...
@@ -130,7 +138,7 @@ private:
// Revert back
std::reverse(text.begin(), text.end());
return text;
}
}
*/
dialogs
::
PreviewUploadOverlay
previewDialog_
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment