mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 12:38:48 +03:00
Mouse selection of completions
This commit is contained in:
parent
7cf66ea4f3
commit
0cf556fa20
2 changed files with 21 additions and 3 deletions
|
@ -11,6 +11,8 @@ Popup {
|
||||||
property var completer
|
property var completer
|
||||||
property bool bottomToTop: true
|
property bool bottomToTop: true
|
||||||
|
|
||||||
|
signal completionClicked(string completion)
|
||||||
|
|
||||||
function up() {
|
function up() {
|
||||||
if (bottomToTop)
|
if (bottomToTop)
|
||||||
down_();
|
down_();
|
||||||
|
@ -76,6 +78,13 @@ Popup {
|
||||||
height: chooser.childrenRect.height + 4
|
height: chooser.childrenRect.height + 4
|
||||||
implicitWidth: chooser.childrenRect.width + 4
|
implicitWidth: chooser.childrenRect.width + 4
|
||||||
|
|
||||||
|
MouseArea {
|
||||||
|
anchors.fill: parent
|
||||||
|
hoverEnabled: true
|
||||||
|
onEntered: popup.currentIndex = model.index
|
||||||
|
onClicked: popup.completionClicked(completer.completionAt(model.index))
|
||||||
|
}
|
||||||
|
|
||||||
DelegateChooser {
|
DelegateChooser {
|
||||||
id: chooser
|
id: chooser
|
||||||
|
|
||||||
|
|
|
@ -70,6 +70,11 @@ Rectangle {
|
||||||
|
|
||||||
property int completerTriggeredAt: -1
|
property int completerTriggeredAt: -1
|
||||||
|
|
||||||
|
function insertCompletion(completion) {
|
||||||
|
textArea.remove(completerTriggeredAt, cursorPosition);
|
||||||
|
textArea.insert(cursorPosition, completion);
|
||||||
|
}
|
||||||
|
|
||||||
placeholderText: qsTr("Write a message...")
|
placeholderText: qsTr("Write a message...")
|
||||||
placeholderTextColor: colors.buttonText
|
placeholderTextColor: colors.buttonText
|
||||||
color: colors.text
|
color: colors.text
|
||||||
|
@ -87,6 +92,7 @@ Rectangle {
|
||||||
}
|
}
|
||||||
onSelectionStartChanged: TimelineManager.timeline.input.updateState(selectionStart, selectionEnd, cursorPosition, text)
|
onSelectionStartChanged: TimelineManager.timeline.input.updateState(selectionStart, selectionEnd, cursorPosition, text)
|
||||||
onSelectionEndChanged: TimelineManager.timeline.input.updateState(selectionStart, selectionEnd, cursorPosition, text)
|
onSelectionEndChanged: TimelineManager.timeline.input.updateState(selectionStart, selectionEnd, cursorPosition, text)
|
||||||
|
// Ensure that we get escape key press events first.
|
||||||
Keys.onShortcutOverride: event.accepted = (completerTriggeredAt != -1 && (event.key === Qt.Key_Escape || event.key === Qt.Key_Tab || event.key === Qt.Key_Enter))
|
Keys.onShortcutOverride: event.accepted = (completerTriggeredAt != -1 && (event.key === Qt.Key_Escape || event.key === Qt.Key_Tab || event.key === Qt.Key_Enter))
|
||||||
Keys.onPressed: {
|
Keys.onPressed: {
|
||||||
if (event.matches(StandardKey.Paste)) {
|
if (event.matches(StandardKey.Paste)) {
|
||||||
|
@ -116,8 +122,7 @@ Rectangle {
|
||||||
popup.completerName = "";
|
popup.completerName = "";
|
||||||
popup.close();
|
popup.close();
|
||||||
if (currentCompletion) {
|
if (currentCompletion) {
|
||||||
textArea.remove(completerTriggeredAt, cursorPosition);
|
textArea.insertCompletion(currentCompletion);
|
||||||
textArea.insert(cursorPosition, currentCompletion);
|
|
||||||
event.accepted = true;
|
event.accepted = true;
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
@ -146,7 +151,11 @@ Rectangle {
|
||||||
}
|
}
|
||||||
target: TimelineManager
|
target: TimelineManager
|
||||||
}
|
}
|
||||||
// Ensure that we get escape key press events first.
|
|
||||||
|
Connections {
|
||||||
|
onCompletionClicked: textArea.insertCompletion(completion)
|
||||||
|
target: popup
|
||||||
|
}
|
||||||
|
|
||||||
Completer {
|
Completer {
|
||||||
id: popup
|
id: popup
|
||||||
|
|
Loading…
Reference in a new issue