Skip to content

Commit

Permalink
Bug 1484119 - part 1: Create HTMLEditor::DeleteTableCellWithTransacti…
Browse files Browse the repository at this point in the history
…on() for internal use of nsITableEditor::DeleteTableCell() r=m_kato

nsITableEditor::DeleteTableCell() is an XPCOM method but used internally.
So, HTMLEditor should implement it with non-virtual method and use it
internally.

Differential Revision: https://phabricator.services.mozilla.com/D6176
  • Loading branch information
masayuki-nakano committed Sep 19, 2018
1 parent c7c1a90 commit 7e50c17
Show file tree
Hide file tree
Showing 4 changed files with 208 additions and 174 deletions.
16 changes: 16 additions & 0 deletions editor/libeditor/HTMLEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -1630,6 +1630,22 @@ class HTMLEditor final : public TextEditor
nsresult
DeleteTableRowWithTransaction(Element& aTableElement, int32_t aRowIndex);

/**
* DeleteTableCellWithTransaction() removes table cell elements. If two or
* more cell elements are selected, this removes all selected cell elements.
* Otherwise, this removes some cell elements starting from selected cell
* element or a cell containing first selection range. When this removes
* last cell element in <tr> or <table>, this removes the <tr> or the
* <table> too. Note that when removing a cell causes number of its row
* becomes less than the others, this method does NOT fill the place with
* rowspan nor colspan. This does not return error even if selection is not
* in cell element, just does nothing.
*
* @param aNumberOfCellsToDelete Number of cells to remove. This is ignored
* if 2 or more cells are selected.
*/
nsresult DeleteTableCellWithTransaction(int32_t aNumberOfCellsToDelete);

/**
* DeleteAllChildrenWithTransaction() removes all children of aElement from
* the tree.
Expand Down
9 changes: 6 additions & 3 deletions editor/libeditor/HTMLEditorDataTransfer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,14 @@ HTMLEditor::DoInsertHTMLWithContext(const nsAString& aInputString,
// Delete whole cells: we will replace with new table content.

// Braces for artificial block to scope AutoSelectionRestorer.
// Save current selection since DeleteTableCell() perturbs it.
// Save current selection since DeleteTableCellWithTransaction() perturbs
// it.
{
AutoSelectionRestorer selectionRestorer(selection, this);
rv = DeleteTableCell(1);
NS_ENSURE_SUCCESS(rv, rv);
rv = DeleteTableCellWithTransaction(1);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
}
// collapse selection to beginning of deleted table content
selection->CollapseToStart(IgnoreErrors());
Expand Down
Loading

0 comments on commit 7e50c17

Please sign in to comment.