summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@theqtcompany.com>2015-06-16 14:23:02 +0200
committerRichard Moe Gustavsen <richard.gustavsen@theqtcompany.com>2015-06-17 13:22:17 +0000
commit7480ab5ce953d9c7450524d59b1f1cff60e4c2c9 (patch)
tree8d042b71dd4c1a87852daa270b993a0829029f40 /src
parent1c49a841d9daa7bc498e35b8cc0331e04e96ec70 (diff)
downloadqtquickcontrols-7480ab5ce953d9c7450524d59b1f1cff60e4c2c9.tar.gz
TextEdit: don't clear selection from EditMenu
The code as it stood ensured that only one input field had a text selection at a time. This is not correct, several text edit fields are allowed to have a selection simultaneously. The code that cleared the selection was found in the updateSelectionItem code. iOS is the only platform using the selectionItem. But looking closer at how selections work on iOS, we don't really need to track the selectionItem after all. It's fine that you need to gain focus on a line edit / text edit before you open the edit menu. Moreover, we also lacked the possibility to open the selection menu when just clicking on a focused line edit. So this patch will therefore just remove all the code that had todo with the selectionItem, and adjust a bit how selections work on iOS. Task-number: QTBUG-41375 Change-Id: I0f3951cb7f53e5adae8d8753a7058ee316825921 Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r--src/controls/Private/EditMenu_ios.qml48
-rw-r--r--src/controls/Private/TextInputWithHandles.qml1
-rw-r--r--src/controls/Private/TextSingleton.qml21
-rw-r--r--src/controls/TextArea.qml1
4 files changed, 14 insertions, 57 deletions
diff --git a/src/controls/Private/EditMenu_ios.qml b/src/controls/Private/EditMenu_ios.qml
index bbd25e1b..7b0787f0 100644
--- a/src/controls/Private/EditMenu_ios.qml
+++ b/src/controls/Private/EditMenu_ios.qml
@@ -41,7 +41,7 @@ import QtQuick.Controls.Private 1.0
Item {
anchors.fill: parent
- property bool __showMenuFromTouchAndHold: false
+ property bool __showMenuFromTouch: false
property Component defaultMenu: Menu {
MenuItem {
@@ -85,46 +85,25 @@ Item {
Connections {
target: mouseArea
- function clearFocusFromOtherItems()
- {
- var selectionItem = TextSingleton.selectionItem;
- if (!selectionItem)
- return;
- var otherPos = selectionItem.cursorPosition;
- selectionItem.select(otherPos, otherPos)
- }
-
onClicked: {
- if (control.menu && getMenuInstance().__popupVisible) {
- select(input.cursorPosition, input.cursorPosition);
- } else {
+ var pos = input.positionAt(mouse.x, mouse.y);
+ var posMoved = (pos !== input.cursorPosition);
+ var popupVisible = (control.menu && getMenuInstance().__popupVisible);
+
+ if (!input.activeFocus)
input.activate();
- clearFocusFromOtherItems();
- }
+ else if (!popupVisible && !posMoved)
+ __showMenuFromTouch = true;
- if (input.activeFocus) {
- var pos = input.positionAt(mouse.x, mouse.y)
- input.moveHandles(pos, pos)
- }
+ input.moveHandles(pos, pos)
+ menuTimer.start();
}
onPressAndHold: {
- var pos = input.positionAt(mouseArea.mouseX, mouseArea.mouseY);
- input.select(pos, pos);
- var hasSelection = selectionStart != selectionEnd;
- if (!control.menu || (input.length > 0 && (!input.activeFocus || hasSelection))) {
- selectWord();
- } else {
- // We don't select anything at this point, the
- // menu will instead offer to select a word.
- __showMenuFromTouchAndHold = true;
- menuTimer.start();
- clearFocusFromOtherItems();
- }
+ __showMenuFromTouch = true;
+ menuTimer.start();
}
- onReleased: __showMenuFromTouchAndHold = false
- onCanceled: __showMenuFromTouchAndHold = false
}
Connections {
@@ -166,7 +145,7 @@ Item {
if (!control.menu)
return;
- if ((__showMenuFromTouchAndHold || selectionStart !== selectionEnd)
+ if ((__showMenuFromTouch || selectionStart !== selectionEnd)
&& control.activeFocus
&& (!cursorHandle.pressed && !selectionHandle.pressed)
&& (!flickable || !flickable.moving)
@@ -178,6 +157,7 @@ Item {
var targetRect = Qt.rect(topLeft.x, topLeft.y, size.width, size.height);
getMenuInstance().__dismissMenu();
getMenuInstance().__popup(targetRect, -1, MenuPrivate.EditMenu);
+ __showMenuFromTouch = false;
} else {
getMenuInstance().__dismissMenu();
}
diff --git a/src/controls/Private/TextInputWithHandles.qml b/src/controls/Private/TextInputWithHandles.qml
index 1c40f588..42e7fde0 100644
--- a/src/controls/Private/TextInputWithHandles.qml
+++ b/src/controls/Private/TextInputWithHandles.qml
@@ -72,7 +72,6 @@ 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 da616367..29161354 100644
--- a/src/controls/Private/TextSingleton.qml
+++ b/src/controls/Private/TextSingleton.qml
@@ -37,25 +37,4 @@
pragma Singleton
import QtQuick 2.2
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 3a90a2cc..23360f06 100644
--- a/src/controls/TextArea.qml
+++ b/src/controls/TextArea.qml
@@ -797,7 +797,6 @@ ScrollView {
blockRecursion = false
}
ensureVisible(cursorRectangle)
- TextSingleton.updateSelectionItem(area)
}
function ensureVisible(rect) {