add initial support of tag suggestion

This commit is contained in:
2016-10-24 08:12:14 +03:00
parent d520f55afc
commit 87406f70c4
6 changed files with 65 additions and 11 deletions

View File

@ -16,12 +16,60 @@
***************************************************************************/
import QtQuick 2.0
import QtQuick.Controls 1.3 as QtControls
import QtQuick.Controls 2.0 as QtControls
QtControls.TextArea {
Item {
width: parent.width
height: parent.height * 4 / 5
textFormat: TextEdit.PlainText
text: plasmoid.configuration.text
property var backend
property alias text: textArea.text
QtControls.TextArea {
id: textArea
anchors.fill: parent
textFormat: TextEdit.PlainText
QtControls.ToolTip {
id: tooltip
}
onTextChanged: {
var currentTag = getLastTag()
// exit if there are spaces or empty
if ((currentTag.indexOf(" ") != -1) || (currentTag.length == 0)) {
tooltip.visible = false
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
tooltip.text = tags
changeTooltipPosition()
tooltip.visible = true
}
}
function changeTooltipPosition() {
tooltip.x = textArea. cursorRectangle.x
tooltip.y = textArea. cursorRectangle.y
}
function getLastTag() {
// get substring to analyze
var substring = textArea.getText(0, textArea.cursorPosition)
// find last position of index in the given substring
var signIndex = substring.lastIndexOf('$') + 1
if ((signIndex == 0) || (signIndex == textArea.cursorPosition))
return ""
// get current tag text
return substring.substr(signIndex)
}
}