mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-29 06:08: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 bool bottomToTop: true
|
||||
|
||||
signal completionClicked(string completion)
|
||||
|
||||
function up() {
|
||||
if (bottomToTop)
|
||||
down_();
|
||||
|
@ -76,6 +78,13 @@ Popup {
|
|||
height: chooser.childrenRect.height + 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 {
|
||||
id: chooser
|
||||
|
||||
|
|
|
@ -70,6 +70,11 @@ Rectangle {
|
|||
|
||||
property int completerTriggeredAt: -1
|
||||
|
||||
function insertCompletion(completion) {
|
||||
textArea.remove(completerTriggeredAt, cursorPosition);
|
||||
textArea.insert(cursorPosition, completion);
|
||||
}
|
||||
|
||||
placeholderText: qsTr("Write a message...")
|
||||
placeholderTextColor: colors.buttonText
|
||||
color: colors.text
|
||||
|
@ -87,6 +92,7 @@ Rectangle {
|
|||
}
|
||||
onSelectionStartChanged: 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.onPressed: {
|
||||
if (event.matches(StandardKey.Paste)) {
|
||||
|
@ -116,8 +122,7 @@ Rectangle {
|
|||
popup.completerName = "";
|
||||
popup.close();
|
||||
if (currentCompletion) {
|
||||
textArea.remove(completerTriggeredAt, cursorPosition);
|
||||
textArea.insert(cursorPosition, currentCompletion);
|
||||
textArea.insertCompletion(currentCompletion);
|
||||
event.accepted = true;
|
||||
return ;
|
||||
}
|
||||
|
@ -146,7 +151,11 @@ Rectangle {
|
|||
}
|
||||
target: TimelineManager
|
||||
}
|
||||
// Ensure that we get escape key press events first.
|
||||
|
||||
Connections {
|
||||
onCompletionClicked: textArea.insertCompletion(completion)
|
||||
target: popup
|
||||
}
|
||||
|
||||
Completer {
|
||||
id: popup
|
||||
|
|
Loading…
Reference in a new issue