diff options
| author | Richard Moe Gustavsen <richard.gustavsen@digia.com> | 2014-08-19 13:16:45 +0200 |
|---|---|---|
| committer | J-P Nurmi <jpnurmi@digia.com> | 2014-09-11 17:29:09 +0200 |
| commit | 080d028c99df0f313f7dddf25da4843dabd57ef5 (patch) | |
| tree | b991fc2bfe94e2af2005b7adaf4bda4735f592b1 /src | |
| parent | 16216d2484492031542e85ae8d73f94f487aba8f (diff) | |
TextSingleton: implement API for getting current item with selection
On some platforms (iOS) you can select text without giving
focus to the input. To be able to clear selection from other
parts of the code (iOS will only let one input have selection
at a time), we need to track this. Later patches will make
use of it.
Change-Id: I4689253b439e0a86349e53c2edf2554fc96225f8
Reviewed-by: J-P Nurmi <jpnurmi@digia.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/controls/Private/TextInputWithHandles.qml | 2 | ||||
| -rw-r--r-- | src/controls/Private/TextSingleton.qml | 24 | ||||
| -rw-r--r-- | src/controls/TextArea.qml | 1 |
3 files changed, 26 insertions, 1 deletions
diff --git a/src/controls/Private/TextInputWithHandles.qml b/src/controls/Private/TextInputWithHandles.qml index cace83f64..59ba971e8 100644 --- a/src/controls/Private/TextInputWithHandles.qml +++ b/src/controls/Private/TextInputWithHandles.qml @@ -38,6 +38,7 @@ ** ****************************************************************************/ import QtQuick 2.2 +import QtQuick.Controls.Private 1.0 TextInput { id: input @@ -71,6 +72,7 @@ TextInput { selectionHandle.position = (selectionStart !== cursorPosition) ? selectionStart : selectionEnd blockRecursion = false } + TextSingleton.updateSelectionItem(input) } function activate() { diff --git a/src/controls/Private/TextSingleton.qml b/src/controls/Private/TextSingleton.qml index 7bccdd552..3ff89af01 100644 --- a/src/controls/Private/TextSingleton.qml +++ b/src/controls/Private/TextSingleton.qml @@ -33,4 +33,26 @@ pragma Singleton import QtQuick 2.2 -Text {} +Text { + /** + selectionItem is the item that currently has a text selection. On some platforms + (iOS) you can select text without activating the input field. This means that + selectionItem can be different from item with active focus on those platforms. + */ + property Item selectionItem: null + + function updateSelectionItem(item) + { + // Convenience function to check if we should transfer or + // remove selectionItem status from item. + var selection = item.selectionStart !== item.selectionEnd + if (item === selectionItem) { + if (!selection) + selectionItem = null + } else if (selection) { + if (selectionItem) + selectionItem.select(selectionItem.cursorPosition, selectionItem.cursorPosition) + selectionItem = item + } + } +} diff --git a/src/controls/TextArea.qml b/src/controls/TextArea.qml index 415098380..6db196b62 100644 --- a/src/controls/TextArea.qml +++ b/src/controls/TextArea.qml @@ -787,6 +787,7 @@ ScrollView { blockRecursion = false } ensureVisible(cursorRectangle) + TextSingleton.updateSelectionItem(area) } function ensureVisible(rect) { |
