mirror of
https://github.com/webodf/WebODF.git
synced 2026-12-01 16:56:05 +01:00
Move the caret also backwards.
This commit is contained in:
@@ -78,6 +78,7 @@ gui.Avatar = function Avatar(memberid, rootNode, positionFilter, caretMover) {
|
||||
var handled = false;
|
||||
if (charCode === 37) { // left
|
||||
moveBackward();
|
||||
caret.focus();
|
||||
handled = true;
|
||||
} else if (charCode === 39) { // right
|
||||
moveForward();
|
||||
@@ -88,7 +89,8 @@ gui.Avatar = function Avatar(memberid, rootNode, positionFilter, caretMover) {
|
||||
}
|
||||
function handleDocumentClick(e) {
|
||||
// figure out how many steps to move to the position
|
||||
var steps = stepCounter.countStepsToPosition(e.target, e.x, e.y);
|
||||
var steps = stepCounter.countStepsToPosition(e.target, e.x, e.y,
|
||||
positionFilter);
|
||||
caretMover(steps);
|
||||
runtime.log(steps);
|
||||
runtime.log(e.target.getBoundingClientRect());
|
||||
|
||||
@@ -63,7 +63,6 @@ gui.Caret = function Caret(rootNode, keyHandler) {
|
||||
}
|
||||
var document = /**@type{!Document}*/(rootNode.ownerDocument),
|
||||
selectionMover = new gui.SelectionMover(rootNode),
|
||||
iterator = selectionMover.createIterator(),
|
||||
htmlns = document.documentElement.namespaceURI,
|
||||
span = document.createElementNS(htmlns, "span"),
|
||||
handle = document.createElementNS(htmlns, "div"),
|
||||
@@ -103,7 +102,7 @@ gui.Caret = function Caret(rootNode, keyHandler) {
|
||||
if (number > 0) {
|
||||
selectionMover.movePointForward(number);
|
||||
} else if (number < 0) {
|
||||
selectionMover.movePointBackward(number);
|
||||
selectionMover.movePointBackward(-number);
|
||||
}
|
||||
updateHandlePosition();
|
||||
};
|
||||
|
||||
@@ -57,8 +57,7 @@ gui.SelectionMover = function SelectionMover(rootNode) {
|
||||
doc = /**@type{!Document}*/(rootNode.ownerDocument),
|
||||
selection = new core.Selection(doc),
|
||||
positionIterator,
|
||||
cursor = new core.Cursor(selection, doc),
|
||||
filter = new CursorFilter();
|
||||
cursor = new core.Cursor(selection, doc);
|
||||
function doMove(steps, extend, move) {
|
||||
var left = steps;
|
||||
// assume positionIterator reflects current state
|
||||
@@ -140,13 +139,18 @@ gui.SelectionMover = function SelectionMover(rootNode) {
|
||||
function countBackwardSteps(steps, filter) {
|
||||
var c = positionIterator.container(),
|
||||
o = positionIterator.offset(),
|
||||
count = 1;
|
||||
stepCount = 0,
|
||||
count = 0;
|
||||
while (steps > 0 && positionIterator.previousPosition()) {
|
||||
stepCount += 1;
|
||||
if (filter.acceptPosition(positionIterator) === 1) {
|
||||
count += stepCount;
|
||||
stepCount = 0;
|
||||
steps -= 1;
|
||||
}
|
||||
count += 1;
|
||||
}
|
||||
positionIterator.setPosition(c, o);
|
||||
return count;
|
||||
}
|
||||
/**
|
||||
@@ -155,7 +159,7 @@ gui.SelectionMover = function SelectionMover(rootNode) {
|
||||
* @param {!number} y
|
||||
* @return {!number}
|
||||
*/
|
||||
function countStepsToPosition(element, x, y) {
|
||||
function countStepsToPosition(element, x, y, filter) {
|
||||
// first figure out how to get to the element
|
||||
// really dumb/inefficient implementation
|
||||
var c = positionIterator.container(),
|
||||
@@ -163,19 +167,24 @@ gui.SelectionMover = function SelectionMover(rootNode) {
|
||||
steps = 0;
|
||||
while (positionIterator.container() !== element
|
||||
&& positionIterator.nextPosition()) {
|
||||
steps += 1;
|
||||
if (filter.acceptPosition(positionIterator) === 1) {
|
||||
steps += 1;
|
||||
}
|
||||
}
|
||||
if (positionIterator.container() !== element) {
|
||||
steps = 0;
|
||||
positionIterator.setPosition(c, o);
|
||||
while (positionIterator.container() !== element
|
||||
&& positionIterator.previousPosition()) {
|
||||
steps -= 1;
|
||||
if (filter.acceptPosition(positionIterator) === 1) {
|
||||
steps -= 1;
|
||||
}
|
||||
}
|
||||
if (positionIterator.container() !== element) {
|
||||
steps = 0;
|
||||
}
|
||||
}
|
||||
positionIterator.setPosition(c, o);
|
||||
runtime.log(" " + steps);
|
||||
runtime.log(" " + element.getBoundingClientRect());
|
||||
return steps;
|
||||
@@ -193,11 +202,9 @@ gui.SelectionMover = function SelectionMover(rootNode) {
|
||||
this.getSelection = function () {
|
||||
return selection;
|
||||
};
|
||||
this.createIterator = function () {
|
||||
return new core.PositionIterator(rootNode, 5, filter, false);
|
||||
};
|
||||
function init() {
|
||||
positionIterator = self.createIterator();
|
||||
var filter = new CursorFilter();
|
||||
positionIterator = new core.PositionIterator(rootNode, 5, filter, false);
|
||||
// put the cursor at the start of the rootNode
|
||||
selection.collapse(positionIterator.container(),
|
||||
positionIterator.offset());
|
||||
@@ -207,12 +214,10 @@ gui.SelectionMover = function SelectionMover(rootNode) {
|
||||
while (self.movePointForward()) {
|
||||
n += 1;
|
||||
}
|
||||
runtime.log("YO " + n);
|
||||
n = 1;
|
||||
while (self.movePointBackward()) {
|
||||
n += 1;
|
||||
}
|
||||
runtime.log("YO " + n);
|
||||
*/
|
||||
}
|
||||
init();
|
||||
|
||||
Reference in New Issue
Block a user