You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@corinthia.apache.org by pm...@apache.org on 2015/02/23 16:33:12 UTC

incubator-corinthia git commit: Fix cursor position in empty caption

Repository: incubator-corinthia
Updated Branches:
  refs/heads/master 13f9a17e7 -> 9a24b3305


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/master
Commit: 9a24b33059ff0b804ad0eae5031531043d870edd
Parents: 13f9a17
Author: Peter Kelly <pe...@uxproductivity.com>
Authored: Mon Feb 23 22:30:43 2015 +0700
Committer: Peter Kelly <pe...@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;