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