2011-04-08 Andrey Adaikin <aandrey@google.com>

        Reviewed by Pavel Feldman.

        Web Inspector: Bugs in some corner cases in the text editor
        https://bugs.webkit.org/show_bug.cgi?id=58025

        This solves the following bugs:
        1) The very last _empty_ line would not be deleted if you hit a Backspace on it, or the selection text to be deleted is extended to the very bottom of the editor.
        2) An odd corner case: delete all source code from the editor, hit backspace on the only empty line, then add a character. In this case the browser will insert a TEXT node instead of a DIV node for a lineRow.

        * inspector/front-end/TextViewer.js:
        (WebInspector.TextEditorMainPanel.prototype._selectionToPosition):
        (WebInspector.TextEditorMainPanel.prototype._enclosingLineRowOrSelf):
        (WebInspector.TextEditorMainPanel.prototype._handleDOMUpdates):
        (WebInspector.TextEditorMainPanel.prototype._applyDomUpdates):
        (WebInspector.TextEditorMainPanel.prototype._collectLinesFromDiv):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@83285 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 68c7ef15
2011-04-08 Andrey Adaikin <aandrey@google.com>
Reviewed by Pavel Feldman.
Web Inspector: Bugs in some corner cases in the text editor
https://bugs.webkit.org/show_bug.cgi?id=58025
This solves the following bugs:
1) The very last _empty_ line would not be deleted if you hit a Backspace on it, or the selection text to be deleted is extended to the very bottom of the editor.
2) An odd corner case: delete all source code from the editor, hit backspace on the only empty line, then add a character. In this case the browser will insert a TEXT node instead of a DIV node for a lineRow.
* inspector/front-end/TextViewer.js:
(WebInspector.TextEditorMainPanel.prototype._selectionToPosition):
(WebInspector.TextEditorMainPanel.prototype._enclosingLineRowOrSelf):
(WebInspector.TextEditorMainPanel.prototype._handleDOMUpdates):
(WebInspector.TextEditorMainPanel.prototype._applyDomUpdates):
(WebInspector.TextEditorMainPanel.prototype._collectLinesFromDiv):
2011-04-07 Pavel Podivilov <podivilov@chromium.org>
Reviewed by Pavel Feldman.
/*
* Copyright (C) 2009 Google Inc. All rights reserved.
* Copyright (C) 2011 Google Inc. All rights reserved.
* Copyright (C) 2010 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
......@@ -1102,14 +1102,14 @@ WebInspector.TextEditorMainPanel.prototype = {
if (container === this._container && offset === 1)
return { line: this._textModel.linesCount - 1, column: this._textModel.lineLength(this._textModel.linesCount - 1) };
var lineRow = container.enclosingNodeOrSelfWithNodeName("DIV");
var lineRow = this._enclosingLineRowOrSelf(container);
var lineNumber = lineRow.lineNumber;
if (container === lineRow && offset === 0)
return { line: lineNumber, column: 0 };
// This may be chunk and chunks may contain \n.
var column = 0;
var node = lineRow.traverseNextTextNode(lineRow);
var node = lineRow.nodeType === Node.TEXT_NODE ? lineRow : lineRow.traverseNextTextNode(lineRow);
while (node && node !== container) {
var text = node.textContent;
for (var i = 0; i < text.length; ++i) {
......@@ -1155,6 +1155,18 @@ WebInspector.TextEditorMainPanel.prototype = {
return rangeBoundary;
},
_enclosingLineRowOrSelf: function(element)
{
var lineRow = element.enclosingNodeOrSelfWithClass("webkit-line-content");
if (lineRow)
return lineRow;
for (var lineRow = element; lineRow; lineRow = lineRow.parentElement) {
if (lineRow.parentElement === this._container)
return lineRow;
}
return null;
},
_appendSpan: function(element, content, className)
{
if (className === "html-resource-link" || className === "html-external-link") {
......@@ -1219,7 +1231,7 @@ WebInspector.TextEditorMainPanel.prototype = {
if (target === this._container)
return;
var lineRow = target.enclosingNodeOrSelfWithClass("webkit-line-content");
var lineRow = this._enclosingLineRowOrSelf(target);
if (!lineRow)
return;
......@@ -1247,7 +1259,7 @@ WebInspector.TextEditorMainPanel.prototype = {
var endLine = startLine + 1;
for (var row = lineRow.nextSibling; row; row = row.nextSibling) {
if (typeof row.lineNumber === "number") {
if (typeof row.lineNumber === "number" && row.lineNumber > startLine) {
endLine = row.lineNumber;
break;
}
......@@ -1334,6 +1346,9 @@ WebInspector.TextEditorMainPanel.prototype = {
if (lines.length === 0 && endLine < this._textModel.linesCount) {
var oldRange = new WebInspector.TextRange(startLine, 0, endLine, 0);
var newRange = this._textModel.setText(oldRange, "");
} else if (lines.length === 0 && startLine > 0) {
var oldRange = new WebInspector.TextRange(startLine - 1, this._textModel.lineLength(startLine - 1), endLine - 1, this._textModel.lineLength(endLine - 1));
var newRange = this._textModel.setText(oldRange, "");
} else {
var oldRange = new WebInspector.TextRange(startLine, 0, endLine - 1, this._textModel.lineLength(endLine - 1));
var newRange = this._textModel.setText(oldRange, lines.join("\n"));
......@@ -1480,7 +1495,7 @@ WebInspector.TextEditorMainPanel.prototype = {
_collectLinesFromDiv: function(lines, element)
{
var textContents = [];
var node = element.traverseNextNode(element);
var node = element.nodeType === Node.TEXT_NODE ? element : element.traverseNextNode(element);
while (node) {
if (element.decorationsElement === node) {
node = node.nextSibling;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment