corinthia-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmke...@apache.org
Subject incubator-corinthia git commit: Fix cursor visibility after inserting a note
Date Tue, 24 Feb 2015 15:47:41 GMT
Repository: incubator-corinthia
Updated Branches:
  refs/heads/master 60e51ed6a -> 8266b657b


Fix cursor visibility after inserting a note

This commit fixes a bug where after inserting a footnote or endnote, and
then moving the cursor to the position directly after it, the cursor
would show up as being inside the brackets, rather than outside.

This was happening because in some cases (such as when the cursor is
part-way through a text node at the time of the insertion), we would end
up with an empty text node appearing directly after the note. The empty
text node came from Formatting_splitAroundSelection.

When the arrow keys were subsequently used to move the cursor past the
last character in the note, it would go into this empty text node.
Position_rectAtPos would not be able to find the proper coordinates for
the empty text node, and thus it would look as though the cursor was
still inside the note, even though it was not.

Now, before doing the actual insertion of a note, we remove the empty
text node, if it's present.

The insertFootnote and insertEndnote tests have now been updated to call
showEmptyTextNodes, but the expected result remains unchanged - since we
should not see any empty text nodes after insertion.


Project: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/commit/8266b657
Tree: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/tree/8266b657
Diff: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/diff/8266b657

Branch: refs/heads/master
Commit: 8266b657b394c07b615f0c820b8c19aa9126ee47
Parents: 60e51ed
Author: Peter Kelly <peter@uxproductivity.com>
Authored: Tue Feb 24 22:04:34 2015 +0700
Committer: Peter Kelly <peter@uxproductivity.com>
Committed: Tue Feb 24 22:04:34 2015 +0700

----------------------------------------------------------------------
 Editor/src/Cursor.js                            | 17 ++++++++++++++++-
 Editor/tests/cursor/insertEndnote01-input.html  |  1 +
 Editor/tests/cursor/insertEndnote02-input.html  |  1 +
 Editor/tests/cursor/insertEndnote03-input.html  |  1 +
 Editor/tests/cursor/insertEndnote04-input.html  |  1 +
 Editor/tests/cursor/insertEndnote05-input.html  |  1 +
 Editor/tests/cursor/insertEndnote06-input.html  |  1 +
 Editor/tests/cursor/insertEndnote07-input.html  |  1 +
 Editor/tests/cursor/insertEndnote08-input.html  |  1 +
 Editor/tests/cursor/insertEndnote09-input.html  |  1 +
 Editor/tests/cursor/insertFootnote01-input.html |  1 +
 Editor/tests/cursor/insertFootnote02-input.html |  1 +
 Editor/tests/cursor/insertFootnote03-input.html |  1 +
 Editor/tests/cursor/insertFootnote04-input.html |  1 +
 Editor/tests/cursor/insertFootnote05-input.html |  1 +
 Editor/tests/cursor/insertFootnote06-input.html |  1 +
 Editor/tests/cursor/insertFootnote07-input.html |  1 +
 Editor/tests/cursor/insertFootnote08-input.html |  1 +
 Editor/tests/cursor/insertFootnote09-input.html |  1 +
 19 files changed, 34 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/8266b657/Editor/src/Cursor.js
----------------------------------------------------------------------
diff --git a/Editor/src/Cursor.js b/Editor/src/Cursor.js
index fcc5280..9b68988 100644
--- a/Editor/src/Cursor.js
+++ b/Editor/src/Cursor.js
@@ -978,7 +978,22 @@ var Cursor_insertEndnote;
         range = moveRangeOutsideOfNote(range);
         Formatting_splitAroundSelection(range,false);
 
-        var pos = Position_preferElementPosition(range.start);
+        // If we're part-way through a text node, splitAroundSelection will give us an
+        // empty text node between the before and after text. For formatting purposes that's
+        // fine (not sure if necessary), but when inserting a footnote or endnote we want
+        // to avoid this as it causes problems with cursor movement - specifically, the cursor
+        // is allowed to go inside the empty text node, and this doesn't show up in the correct
+        // position on screen.
+        var pos = range.start;
+        if ((pos.node._type == HTML_TEXT) &&
+            (pos.node.nodeValue.length == 0)) {
+            var empty = pos.node;
+            pos = new Position(empty.parentNode,DOM_nodeOffset(empty));
+            DOM_deleteNode(empty);
+        }
+        else {
+            pos = Position_preferElementPosition(pos);
+        }
 
         DOM_insertBefore(pos.node,footnote,pos.node.childNodes[pos.offset]);
         Selection_set(footnote,0,footnote,footnote.childNodes.length);

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/8266b657/Editor/tests/cursor/insertEndnote01-input.html
----------------------------------------------------------------------
diff --git a/Editor/tests/cursor/insertEndnote01-input.html b/Editor/tests/cursor/insertEndnote01-input.html
index 9ff5e4d..8a52b5c 100644
--- a/Editor/tests/cursor/insertEndnote01-input.html
+++ b/Editor/tests/cursor/insertEndnote01-input.html
@@ -5,6 +5,7 @@
 function performTest()
 {
     Cursor_insertEndnote("Endnote content");
+    Selection_preserveWhileExecuting(showEmptyTextNodes);
     showSelection();
 }
 </script>

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/8266b657/Editor/tests/cursor/insertEndnote02-input.html
----------------------------------------------------------------------
diff --git a/Editor/tests/cursor/insertEndnote02-input.html b/Editor/tests/cursor/insertEndnote02-input.html
index 1074b1c..0875055 100644
--- a/Editor/tests/cursor/insertEndnote02-input.html
+++ b/Editor/tests/cursor/insertEndnote02-input.html
@@ -5,6 +5,7 @@
 function performTest()
 {
     Cursor_insertEndnote("Endnote content");
+    Selection_preserveWhileExecuting(showEmptyTextNodes);
     showSelection();
 }
 </script>

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/8266b657/Editor/tests/cursor/insertEndnote03-input.html
----------------------------------------------------------------------
diff --git a/Editor/tests/cursor/insertEndnote03-input.html b/Editor/tests/cursor/insertEndnote03-input.html
index 9226476..b10fba6 100644
--- a/Editor/tests/cursor/insertEndnote03-input.html
+++ b/Editor/tests/cursor/insertEndnote03-input.html
@@ -5,6 +5,7 @@
 function performTest()
 {
     Cursor_insertEndnote("Endnote content");
+    Selection_preserveWhileExecuting(showEmptyTextNodes);
     showSelection();
 }
 </script>

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/8266b657/Editor/tests/cursor/insertEndnote04-input.html
----------------------------------------------------------------------
diff --git a/Editor/tests/cursor/insertEndnote04-input.html b/Editor/tests/cursor/insertEndnote04-input.html
index 73cc7c4..5063da9 100644
--- a/Editor/tests/cursor/insertEndnote04-input.html
+++ b/Editor/tests/cursor/insertEndnote04-input.html
@@ -5,6 +5,7 @@
 function performTest()
 {
     Cursor_insertEndnote("Endnote content");
+    Selection_preserveWhileExecuting(showEmptyTextNodes);
     showSelection();
 }
 </script>

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/8266b657/Editor/tests/cursor/insertEndnote05-input.html
----------------------------------------------------------------------
diff --git a/Editor/tests/cursor/insertEndnote05-input.html b/Editor/tests/cursor/insertEndnote05-input.html
index 04eac74..10e397f 100644
--- a/Editor/tests/cursor/insertEndnote05-input.html
+++ b/Editor/tests/cursor/insertEndnote05-input.html
@@ -5,6 +5,7 @@
 function performTest()
 {
     Cursor_insertEndnote("Endnote content");
+    Selection_preserveWhileExecuting(showEmptyTextNodes);
     showSelection();
 }
 </script>

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/8266b657/Editor/tests/cursor/insertEndnote06-input.html
----------------------------------------------------------------------
diff --git a/Editor/tests/cursor/insertEndnote06-input.html b/Editor/tests/cursor/insertEndnote06-input.html
index a527c5e..040d642 100644
--- a/Editor/tests/cursor/insertEndnote06-input.html
+++ b/Editor/tests/cursor/insertEndnote06-input.html
@@ -5,6 +5,7 @@
 function performTest()
 {
     Cursor_insertEndnote("Endnote content");
+    Selection_preserveWhileExecuting(showEmptyTextNodes);
     showSelection();
 }
 </script>

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/8266b657/Editor/tests/cursor/insertEndnote07-input.html
----------------------------------------------------------------------
diff --git a/Editor/tests/cursor/insertEndnote07-input.html b/Editor/tests/cursor/insertEndnote07-input.html
index 77c4adc..e4b618a 100644
--- a/Editor/tests/cursor/insertEndnote07-input.html
+++ b/Editor/tests/cursor/insertEndnote07-input.html
@@ -5,6 +5,7 @@
 function performTest()
 {
     Cursor_insertEndnote("Endnote content");
+    Selection_preserveWhileExecuting(showEmptyTextNodes);
     showSelection();
 }
 </script>

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/8266b657/Editor/tests/cursor/insertEndnote08-input.html
----------------------------------------------------------------------
diff --git a/Editor/tests/cursor/insertEndnote08-input.html b/Editor/tests/cursor/insertEndnote08-input.html
index fab5957..5c5fa70 100644
--- a/Editor/tests/cursor/insertEndnote08-input.html
+++ b/Editor/tests/cursor/insertEndnote08-input.html
@@ -5,6 +5,7 @@
 function performTest()
 {
     Cursor_insertEndnote("Endnote content");
+    Selection_preserveWhileExecuting(showEmptyTextNodes);
     showSelection();
 }
 </script>

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/8266b657/Editor/tests/cursor/insertEndnote09-input.html
----------------------------------------------------------------------
diff --git a/Editor/tests/cursor/insertEndnote09-input.html b/Editor/tests/cursor/insertEndnote09-input.html
index 06dd1f6..d915ef5 100644
--- a/Editor/tests/cursor/insertEndnote09-input.html
+++ b/Editor/tests/cursor/insertEndnote09-input.html
@@ -5,6 +5,7 @@
 function performTest()
 {
     Cursor_insertEndnote("Endnote content");
+    Selection_preserveWhileExecuting(showEmptyTextNodes);
     showSelection();
 }
 </script>

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/8266b657/Editor/tests/cursor/insertFootnote01-input.html
----------------------------------------------------------------------
diff --git a/Editor/tests/cursor/insertFootnote01-input.html b/Editor/tests/cursor/insertFootnote01-input.html
index 7d4852c..22c102b 100644
--- a/Editor/tests/cursor/insertFootnote01-input.html
+++ b/Editor/tests/cursor/insertFootnote01-input.html
@@ -5,6 +5,7 @@
 function performTest()
 {
     Cursor_insertFootnote("Footnote content");
+    Selection_preserveWhileExecuting(showEmptyTextNodes);
     showSelection();
 }
 </script>

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/8266b657/Editor/tests/cursor/insertFootnote02-input.html
----------------------------------------------------------------------
diff --git a/Editor/tests/cursor/insertFootnote02-input.html b/Editor/tests/cursor/insertFootnote02-input.html
index 0957ba4..e1ac92a 100644
--- a/Editor/tests/cursor/insertFootnote02-input.html
+++ b/Editor/tests/cursor/insertFootnote02-input.html
@@ -5,6 +5,7 @@
 function performTest()
 {
     Cursor_insertFootnote("Footnote content");
+    Selection_preserveWhileExecuting(showEmptyTextNodes);
     showSelection();
 }
 </script>

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/8266b657/Editor/tests/cursor/insertFootnote03-input.html
----------------------------------------------------------------------
diff --git a/Editor/tests/cursor/insertFootnote03-input.html b/Editor/tests/cursor/insertFootnote03-input.html
index ec62f58..b24f4df 100644
--- a/Editor/tests/cursor/insertFootnote03-input.html
+++ b/Editor/tests/cursor/insertFootnote03-input.html
@@ -5,6 +5,7 @@
 function performTest()
 {
     Cursor_insertFootnote("Footnote content");
+    Selection_preserveWhileExecuting(showEmptyTextNodes);
     showSelection();
 }
 </script>

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/8266b657/Editor/tests/cursor/insertFootnote04-input.html
----------------------------------------------------------------------
diff --git a/Editor/tests/cursor/insertFootnote04-input.html b/Editor/tests/cursor/insertFootnote04-input.html
index 22d9e2d..5e8ee78 100644
--- a/Editor/tests/cursor/insertFootnote04-input.html
+++ b/Editor/tests/cursor/insertFootnote04-input.html
@@ -5,6 +5,7 @@
 function performTest()
 {
     Cursor_insertFootnote("Footnote content");
+    Selection_preserveWhileExecuting(showEmptyTextNodes);
     showSelection();
 }
 </script>

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/8266b657/Editor/tests/cursor/insertFootnote05-input.html
----------------------------------------------------------------------
diff --git a/Editor/tests/cursor/insertFootnote05-input.html b/Editor/tests/cursor/insertFootnote05-input.html
index 5c3885e..a976635 100644
--- a/Editor/tests/cursor/insertFootnote05-input.html
+++ b/Editor/tests/cursor/insertFootnote05-input.html
@@ -5,6 +5,7 @@
 function performTest()
 {
     Cursor_insertFootnote("Footnote content");
+    Selection_preserveWhileExecuting(showEmptyTextNodes);
     showSelection();
 }
 </script>

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/8266b657/Editor/tests/cursor/insertFootnote06-input.html
----------------------------------------------------------------------
diff --git a/Editor/tests/cursor/insertFootnote06-input.html b/Editor/tests/cursor/insertFootnote06-input.html
index 9452059..d4c318c 100644
--- a/Editor/tests/cursor/insertFootnote06-input.html
+++ b/Editor/tests/cursor/insertFootnote06-input.html
@@ -5,6 +5,7 @@
 function performTest()
 {
     Cursor_insertFootnote("Footnote content");
+    Selection_preserveWhileExecuting(showEmptyTextNodes);
     showSelection();
 }
 </script>

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/8266b657/Editor/tests/cursor/insertFootnote07-input.html
----------------------------------------------------------------------
diff --git a/Editor/tests/cursor/insertFootnote07-input.html b/Editor/tests/cursor/insertFootnote07-input.html
index 161adc8..98ed6d9 100644
--- a/Editor/tests/cursor/insertFootnote07-input.html
+++ b/Editor/tests/cursor/insertFootnote07-input.html
@@ -5,6 +5,7 @@
 function performTest()
 {
     Cursor_insertFootnote("Footnote content");
+    Selection_preserveWhileExecuting(showEmptyTextNodes);
     showSelection();
 }
 </script>

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/8266b657/Editor/tests/cursor/insertFootnote08-input.html
----------------------------------------------------------------------
diff --git a/Editor/tests/cursor/insertFootnote08-input.html b/Editor/tests/cursor/insertFootnote08-input.html
index b159a66..695c7d5 100644
--- a/Editor/tests/cursor/insertFootnote08-input.html
+++ b/Editor/tests/cursor/insertFootnote08-input.html
@@ -5,6 +5,7 @@
 function performTest()
 {
     Cursor_insertFootnote("Footnote content");
+    Selection_preserveWhileExecuting(showEmptyTextNodes);
     showSelection();
 }
 </script>

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/8266b657/Editor/tests/cursor/insertFootnote09-input.html
----------------------------------------------------------------------
diff --git a/Editor/tests/cursor/insertFootnote09-input.html b/Editor/tests/cursor/insertFootnote09-input.html
index 136b643..9feec88 100644
--- a/Editor/tests/cursor/insertFootnote09-input.html
+++ b/Editor/tests/cursor/insertFootnote09-input.html
@@ -5,6 +5,7 @@
 function performTest()
 {
     Cursor_insertFootnote("Footnote content");
+    Selection_preserveWhileExecuting(showEmptyTextNodes);
     showSelection();
 }
 </script>


Mime
View raw message