improve tag completion

allow to select item from tooltip by mouse and insert it to text edtior
This commit is contained in:
Evgenii Alekseev 2016-10-25 10:23:05 +03:00
parent 87406f70c4
commit c3c46ff1b1
2 changed files with 25 additions and 10 deletions

View File

@ -33,6 +33,22 @@ Item {
QtControls.ToolTip { QtControls.ToolTip {
id: tooltip id: tooltip
property string substring
property var tags: []
text: tags.join('\n')
bottomPadding: 0
topPadding: 0
MouseArea {
anchors.fill: parent
onClicked: {
var tagHeight = tooltip.height / tooltip.tags.length
var pos = Math.round(mouse.y / tagHeight, 0)
appendTag(tooltip.tags[pos], tooltip.substring)
}
}
} }
onTextChanged: { onTextChanged: {
@ -42,19 +58,18 @@ Item {
tooltip.visible = false tooltip.visible = false
return return
} }
var tags = backend.dictKeys(true, "^" + currentTag).join('\n')
// exit if no suggestion found
if (tags.length == 0) {
tooltip.visible = false
return
}
// update tooltip and show it // update tooltip and show it
tooltip.text = tags tooltip.substring = currentTag
tooltip.tags = backend.dictKeys(true, "^" + tooltip.substring)
changeTooltipPosition() changeTooltipPosition()
tooltip.visible = true tooltip.visible = (tooltip.tags.length != 0)
} }
} }
function appendTag(tag, substring) {
textArea.insert(textArea.cursorPosition, tag.substring(substring.length))
}
function changeTooltipPosition() { function changeTooltipPosition() {
tooltip.x = textArea. cursorRectangle.x tooltip.x = textArea. cursorRectangle.x
tooltip.y = textArea. cursorRectangle.y tooltip.y = textArea. cursorRectangle.y