fix: show formation menu in middle of selection or above double click

This commit is contained in:
Jonathan Rainville 2021-04-01 16:00:30 -04:00 committed by Iuri Matias
parent 8b3ce83d00
commit 4af1135f6c
1 changed files with 10 additions and 1 deletions

View File

@ -781,6 +781,8 @@ Rectangle {
ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
TextArea {
property var lastClick: 0
id: messageInputField
textFormat: Text.RichText
font.pixelSize: 15
@ -803,11 +805,18 @@ Rectangle {
selectionColor: Style.current.primarySelectionColor
persistentSelection: true
onReleased: function (event) {
const now = Date.now()
if (messageInputField.selectedText.trim() !== "") {
let x = event.x - (textFormatMenu.width / 2)
// If it's a double click, just check the mouse position
// If it's a mouse select, use the start and end position average)
let x = now < messageInputField.lastClick + 500 ? x = event.x :
(messageInputField.cursorRectangle.x + event.x) / 2
x -= textFormatMenu.width / 2
textFormatMenu.popup(x, -messageInputField.height-2)
messageInputField.forceActiveFocus();
}
lastClick = now
}
StatusTextFormatMenu {