corinthia-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject [1/3] incubator-corinthia git commit: Fix cursor position in empty caption
Date Mon, 23 Feb 2015 19:26:26 GMT
Repository: incubator-corinthia
Updated Branches:
  refs/heads/experimentzip 1baa03dc2 -> 5a745c873


Fix cursor position in empty caption

This commit fixes a bug where if you place the cursor inside an empty
figure or table caption, it's displayed at the left of the screen,
instead of directly after the "Table X: " or "Figure X: " generated
content.

We can't directly get the bounding rect of generated content, so we
temporarily insert a text node containing a single space character, get
the position to the right of that character, and then remove the text
node. This allows us to show the user the position at which text will be
inserted if they start entering text in the caption.


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

Branch: refs/heads/experimentzip
Commit: 9a24b33059ff0b804ad0eae5031531043d870edd
Parents: 13f9a17
Author: Peter Kelly <peter@uxproductivity.com>
Authored: Mon Feb 23 22:30:43 2015 +0700
Committer: Peter Kelly <peter@uxproductivity.com>
Committed: Mon Feb 23 22:30:43 2015 +0700

----------------------------------------------------------------------
 Editor/src/Position.js | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/9a24b330/Editor/src/Position.js
----------------------------------------------------------------------
diff --git a/Editor/src/Position.js b/Editor/src/Position.js
index e767a46..9751743 100644
--- a/Editor/src/Position.js
+++ b/Editor/src/Position.js
@@ -711,6 +711,16 @@ var Position_atPoint;
         return null;
     }
 
+    function findCaptionContainingPos(pos)
+    {
+        var node = Position_closestActualNode(pos);
+        for (; node != null; node = node.parentNode) {
+            if ((node._type == HTML_FIGCAPTION) || (node._type == HTML_CAPTION))
+                return node;
+        }
+        return null;
+    }
+
     function exactRectAtPos(pos)
     {
         var node = pos.node;
@@ -778,6 +788,21 @@ var Position_atPoint;
         if ((noteNode != null) && !nodeHasContent(noteNode)) // In empty footnote
or endnote
             return zeroWidthMidRect(noteNode.getBoundingClientRect());
 
+        var captionNode = findCaptionContainingPos(pos);
+        if ((captionNode != null) && !nodeHasContent(captionNode)) {
+            // Even if an empty caption has generated content (e.g. "Figure X: ") preceding
it,
+            // we can't directly get the rect of that generated content. So we temporarily
insert
+            // a text node containing a single space character, get the position to the right
of
+            // that character, and then remove the text node.
+            var space = DOM_createTextNode(document,String.fromCharCode(160));
+            DOM_appendChild(captionNode,space);
+            var range = new Range(space,1,space,1);
+            var rects = Range_getClientRects(range);
+            DOM_deleteNode(space);
+            if (rects.length > 0)
+                return rects[0];
+        }
+
         var paragraph = Text_findParagraphBoundaries(pos);
 
         var backRect = null;


Mime
View raw message