mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-07-06 02:15:52 +00:00
add initial support of tag suggestion
This commit is contained in:
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user