Skip to content

Commit

Permalink
fixed lineEnd key inside a table cell; fixed lineEnd key inside a DNB…
Browse files Browse the repository at this point in the history
…lock with firefox; fixed potential NPE with lineEnd and lineStart; switching table cells with tab key
  • Loading branch information
damien-git committed Apr 5, 2017
1 parent 85b1b81 commit c9d8bec
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
45 changes: 41 additions & 4 deletions lib/src/cursor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ class Cursor {
*/
void lineStart() {
Point pt = selectionStart.positionOnScreen();
if (pt == null)
return;
//pt.x = 0;
// this does not work when blocks are used (it moves the cursor outside)
DaxeNode dn = selectionStart.dn;
Expand All @@ -315,6 +317,8 @@ class Cursor {
*/
void lineEnd() {
Point pt = selectionStart.positionOnScreen();
if (pt == null)
return;
//pt.x += 10000;
// this does not work when blocks are used (it moves the cursor outside)
DaxeNode dn = selectionStart.dn;
Expand All @@ -324,7 +328,7 @@ class Cursor {
dn = dn.parent;
h.Element hnode = dn.getHTMLNode();
h.Rectangle rect = hnode.getBoundingClientRect();
pt.x = rect.right - 1;
pt.x = rect.right - 2;
pt.y += 5;
Position pos = doc.findPosition(pt.x, pt.y);
if (pos == null)
Expand Down Expand Up @@ -622,7 +626,8 @@ class Cursor {

/**
* Action for the tab key.
* Only does something if spaces are preserved in the element
* Moves the cursor to the next cell in a table.
* Inserts spaces if spaces are preserved in the element
* (without looking at parents).
* If selection is empty, inserts 4 spaces.
* If a text node is selected from the start or a new line,
Expand Down Expand Up @@ -651,8 +656,39 @@ class Cursor {
}
}
}
if (!spacePreserve)
if (!spacePreserve) {
DNTD cell = null;
while (parent != null) {
if (parent is DNTD) {
cell = parent;
break;
}
parent = parent.parent;
}
if (cell != null) {
// switch to next/previous cell if possible
DNTD newCell = null;
if (!shift) {
if (cell.nextSibling is DNTD)
newCell = cell.nextSibling;
else if (cell.parent != null && cell.parent.nextSibling != null &&
cell.parent.nextSibling.firstChild is DNTD)
newCell = cell.parent.nextSibling.firstChild;
} else {
if (cell.previousSibling is DNTD)
newCell = cell.previousSibling;
else if (cell.parent != null && cell.parent.previousSibling != null &&
cell.parent.previousSibling.lastChild is DNTD)
newCell = cell.parent.previousSibling.lastChild;
}
if (newCell != null) {
event.preventDefault();
page.moveCursorTo(new Position(newCell, newCell.offsetLength));
page.updateAfterPathChange();
}
}
return;
}
if (selectionStart != selectionEnd) {
// for a block of text
if (selectionStart.dn is! DNText || selectionEnd.dn is! DNText ||
Expand Down Expand Up @@ -708,7 +744,8 @@ class Cursor {
dn2 = new DNText(s2);
edit.addSubEdit(new UndoableEdit.insertNode(dnpos, dn2));
doc.doNewEdit(edit);
page.cursor.setSelection(new Position(dn2, offset1), new Position(dn2, newEnd));
setSelection(new Position(dn2, offset1), new Position(dn2, newEnd));
page.scrollToPosition(selectionStart);
event.preventDefault();
return;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/src/daxe_node.dart
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ abstract class DaxeNode {
return(true);
h.Element hnode = getHTMLNode();
return(hnode is h.DivElement || hnode is h.ParagraphElement || hnode is h.TableElement ||
hnode is h.TableRowElement || hnode is h.UListElement || hnode is h.LIElement);
hnode is h.TableRowElement || hnode is h.TableCellElement || hnode is h.UListElement ||
hnode is h.LIElement);
}

/**
Expand Down
6 changes: 5 additions & 1 deletion lib/src/web_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,11 @@ class WebPage {

void scrollToNode(DaxeNode dn) {
Position startPos = new Position(dn.parent, dn.parent.offsetOf(dn));
Point pt = startPos.positionOnScreen();
scrollToPosition(startPos);
}

void scrollToPosition(Position pos) {
Point pt = pos.positionOnScreen();
if (pt == null)
return;
h.DivElement doc1 = h.document.getElementById('doc1');
Expand Down

0 comments on commit c9d8bec

Please sign in to comment.