Cursor moves before last word: close completion UI
This commit is contained in:
parent
063f9d2b1d
commit
1b919ec7be
|
@ -55,7 +55,7 @@ Rectangle {
|
|||
onAutoCompletePrevious: userCompletion.previous()
|
||||
onAutoCompleteNext: userCompletion.next()
|
||||
onCancelAutoCompletion: userCompletion.cancel()
|
||||
onExtraCharacterCloseAutoCompletion:
|
||||
onAcceptAutoCompletion:
|
||||
! userCompletion.autoOpen ||
|
||||
userCompletion.autoOpenCompleted ?
|
||||
userCompletion.accept() :
|
||||
|
|
|
@ -55,7 +55,7 @@ HTextArea {
|
|||
|
||||
signal autoCompletePrevious()
|
||||
signal autoCompleteNext()
|
||||
signal extraCharacterCloseAutoCompletion()
|
||||
signal acceptAutoCompletion()
|
||||
signal cancelAutoCompletion()
|
||||
|
||||
function setTyping(typing) {
|
||||
|
@ -189,7 +189,7 @@ HTextArea {
|
|||
autoCompletionOpen ? cancelAutoCompletion() : clearReplyTo()
|
||||
|
||||
Keys.onReturnPressed: ev => {
|
||||
if (autoCompletionOpen) extraCharacterCloseAutoCompletion()
|
||||
if (autoCompletionOpen) acceptAutoCompletion()
|
||||
ev.accepted = true
|
||||
|
||||
ev.modifiers & Qt.ShiftModifier ||
|
||||
|
@ -202,7 +202,7 @@ HTextArea {
|
|||
Keys.onEnterPressed: ev => Keys.returnPressed(ev)
|
||||
|
||||
Keys.onMenuPressed: ev => {
|
||||
if (autoCompletionOpen) extraCharacterCloseAutoCompletion()
|
||||
if (autoCompletionOpen) acceptAutoCompletion()
|
||||
|
||||
if (eventList && eventList.currentItem)
|
||||
eventList.currentItem.openContextMenu()
|
||||
|
@ -235,7 +235,7 @@ HTextArea {
|
|||
}
|
||||
|
||||
Keys.onPressed: ev => {
|
||||
if (ev.text && autoCompletionOpen) extraCharacterCloseAutoCompletion()
|
||||
if (ev.text && autoCompletionOpen) acceptAutoCompletion()
|
||||
|
||||
if (ev.matches(StandardKey.Copy) &&
|
||||
! area.selectedText &&
|
||||
|
|
|
@ -7,7 +7,6 @@ import "../../../Base"
|
|||
import "../../../Base/HTile"
|
||||
|
||||
// FIXME: a b -> a @p b → @p doesn't trigger completion
|
||||
// FIXME: close autocomplete when cursor moves away
|
||||
HListView {
|
||||
id: root
|
||||
|
||||
|
@ -28,13 +27,18 @@ HListView {
|
|||
) :
|
||||
""
|
||||
|
||||
function getLastWordStart() {
|
||||
const lastWordMatch = /(?:^|\s)[^\s]+$/.exec(textArea.text)
|
||||
if (! lastWordMatch) return textArea.length
|
||||
|
||||
if (! (lastWordMatch.index === 0 && ! textArea.text[0].match(/\s/)))
|
||||
return lastWordMatch.index + 1
|
||||
|
||||
return lastWordMatch.index
|
||||
}
|
||||
|
||||
function replaceLastWord(withText) {
|
||||
let lastWordStart = /(?:^|\s)[^\s]+$/.exec(textArea.text).index
|
||||
|
||||
if (! (lastWordStart === 0 && ! textArea.text[0].match(/\s/)))
|
||||
lastWordStart += 1
|
||||
|
||||
textArea.remove(lastWordStart, textArea.length)
|
||||
textArea.remove(getLastWordStart(), textArea.length)
|
||||
textArea.insertAtCursor(withText)
|
||||
}
|
||||
|
||||
|
@ -121,6 +125,11 @@ HListView {
|
|||
Connections {
|
||||
target: root.textArea
|
||||
|
||||
function onCursorPositionChanged() {
|
||||
if (root.open && root.textArea.cursorPosition < getLastWordStart())
|
||||
root.accept()
|
||||
}
|
||||
|
||||
function onTextChanged() {
|
||||
let changed = false
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user