Esanders has uploaded a new change for review.
https://gerrit.wikimedia.org/r/172039
Change subject: Register select all as a command and perform programmatically
......................................................................
Register select all as a command and perform programmatically
This fixes the following issues:
* Not working when a focusable node selected
* Not working when a table selected, now selects
the entire table
* Sometimes not working when a table cell is being edited
* Potential to have a select all tool
* Generally being less at the whim of content editable
It does not fix the ce-false-first-or-last-child issue in Chrome.
Change-Id: Ica731c596af9e6e3495298105ef1e79ba5cccd63
---
M i18n/en.json
M i18n/qqq.json
M src/ce/ve.ce.Surface.js
M src/dm/ve.dm.SurfaceFragment.js
M src/init/ve.init.Target.js
M src/ui/actions/ve.ui.ContentAction.js
M src/ui/dialogs/ve.ui.CommandHelpDialog.js
M src/ui/ve.ui.CommandRegistry.js
M src/ui/ve.ui.TriggerRegistry.js
9 files changed, 56 insertions(+), 2 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor
refs/changes/39/172039/1
diff --git a/i18n/en.json b/i18n/en.json
index 9ee33c0..7ee4b04 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -35,6 +35,7 @@
"visualeditor-commentinspector-edit": "Edit comment",
"visualeditor-commentinspector-title": "Comment",
"visualeditor-commentinspector-tooltip": "Comment",
+ "visualeditor-content-select-all": "Select all",
"visualeditor-contextitemwidget-label-secondary": "Edit",
"visualeditor-dialog-action-apply": "Apply changes",
"visualeditor-dialog-action-cancel": "Cancel",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index f096b3a..d8fe16f 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -41,6 +41,7 @@
"visualeditor-commentinspector-edit": "Label for the edit button in the
comment inspector.",
"visualeditor-commentinspector-title": "{{Identical|Comment}}",
"visualeditor-commentinspector-tooltip": "Tooltip text for comment
button.\n{{Related|Visualeditor-annotationbutton}}\n{{Identical|Comment}}",
+ "visualeditor-content-select-all": "Label for select all command.",
"visualeditor-contextitemwidget-label-secondary": "Text explaining the
action that takes place after clicking on a context item.\n{{Identical|Edit}}",
"visualeditor-dialog-action-apply": "Label text for button to apply
changes made in dialog.\n\nSee also:\n*
{{msg-mw|Visualeditor-dialog-action-cancel}}\n*
{{msg-mw|Visualeditor-dialog-action-done}}\n*
{{msg-mw|Visualeditor-dialog-action-goback}}\n*
{{msg-mw|Visualeditor-dialog-action-insert}}\n{{Identical|Apply change}}",
"visualeditor-dialog-action-cancel": "Label text for button to exit
from dialog without making changes.\n\nSee also:\n*
{{msg-mw|Visualeditor-dialog-action-apply}}\n*
{{msg-mw|Visualeditor-dialog-action-done}}\n*
{{msg-mw|Visualeditor-dialog-action-goback}}\n*
{{msg-mw|Visualeditor-dialog-action-insert}}\n{{Identical|Cancel}}",
diff --git a/src/ce/ve.ce.Surface.js b/src/ce/ve.ce.Surface.js
index 4c6ec40..1ea0413 100644
--- a/src/ce/ve.ce.Surface.js
+++ b/src/ce/ve.ce.Surface.js
@@ -1740,6 +1740,37 @@
};
/**
+ * Select all the contents within the current context
+ */
+ve.ce.Surface.prototype.selectAll = function () {
+ var internalListRange, range, matrix,
+ selection = this.getModel().getSelection();
+
+ if ( selection instanceof ve.dm.LinearSelection ) {
+ if ( this.getActiveTableNode() &&
this.getActiveTableNode().getEditingFragment() ) {
+ range = this.getActiveTableNode().getEditingRange();
+ range = new ve.Range( range.from + 1, range.to - 1 );
+ } else {
+ internalListRange =
this.getModel().getDocument().getInternalList().getListNode().getOuterRange();
+ range = new ve.Range(
+ this.getNearestCorrectOffset( 0, 1 ),
+ this.getNearestCorrectOffset(
internalListRange.start, -1 )
+ );
+ }
+ this.getModel().setLinearSelection( range );
+ } else if ( selection instanceof ve.dm.TableSelection ) {
+ matrix = selection.getTableNode().getMatrix();
+ this.getModel().setSelection(
+ new ve.dm.TableSelection(
+ selection.getDocument(), selection.tableRange,
+ 0, 0, matrix.getColCount(), matrix.getRowCount()
+ )
+ );
+
+ }
+};
+
+/**
* Handle document composition end events.
*
* @method
@@ -2330,6 +2361,7 @@
/**
* Move the DM surface cursor
+ *
* @param {number} offset Distance to move (negative = toward document start)
*/
ve.ce.Surface.prototype.moveModelCursor = function ( offset ) {
diff --git a/src/dm/ve.dm.SurfaceFragment.js b/src/dm/ve.dm.SurfaceFragment.js
index 8295f62..673d70b 100644
--- a/src/dm/ve.dm.SurfaceFragment.js
+++ b/src/dm/ve.dm.SurfaceFragment.js
@@ -791,7 +791,7 @@
return this;
}
- // If selection spans entire document (e.g. CTRL+A in Firefox) then
+ // If selection spans entire document (selectAll) then
// replace with an empty paragraph
internalListRange =
this.document.getInternalList().getListNode().getOuterRange();
if ( rangeToRemove.start === 0 && rangeToRemove.end >=
internalListRange.start ) {
diff --git a/src/init/ve.init.Target.js b/src/init/ve.init.Target.js
index 3df55e1..ba5550c 100644
--- a/src/init/ve.init.Target.js
+++ b/src/init/ve.init.Target.js
@@ -164,6 +164,7 @@
'heading5',
'heading6',
'preformatted',
+ 'selectAll',
'pasteSpecial'
];
diff --git a/src/ui/actions/ve.ui.ContentAction.js
b/src/ui/actions/ve.ui.ContentAction.js
index 81249a4..8a760cd 100644
--- a/src/ui/actions/ve.ui.ContentAction.js
+++ b/src/ui/actions/ve.ui.ContentAction.js
@@ -31,7 +31,7 @@
* @static
* @property
*/
-ve.ui.ContentAction.static.methods = [ 'insert', 'remove', 'select',
'pasteSpecial' ];
+ve.ui.ContentAction.static.methods = [ 'insert', 'remove', 'select',
'pasteSpecial', 'selectAll' ];
/* Methods */
@@ -66,6 +66,15 @@
};
/**
+ * Select all content.
+ *
+ * @method
+ */
+ve.ui.ContentAction.prototype.selectAll = function () {
+ this.surface.getView().selectAll();
+};
+
+/**
* Paste special.
*
* @method
diff --git a/src/ui/dialogs/ve.ui.CommandHelpDialog.js
b/src/ui/dialogs/ve.ui.CommandHelpDialog.js
index c0ac978..c9c6663 100644
--- a/src/ui/dialogs/ve.ui.CommandHelpDialog.js
+++ b/src/ui/dialogs/ve.ui.CommandHelpDialog.js
@@ -182,6 +182,7 @@
other: {
title: 'visualeditor-shortcuts-other',
commands: [
+ { trigger: 'selectAll', msg:
'visualeditor-content-select-all' },
{ trigger: 'commandHelp', msg:
'visualeditor-dialog-command-help-title' }
]
}
diff --git a/src/ui/ve.ui.CommandRegistry.js b/src/ui/ve.ui.CommandRegistry.js
index 4d6398f..a5cc89b 100644
--- a/src/ui/ve.ui.CommandRegistry.js
+++ b/src/ui/ve.ui.CommandRegistry.js
@@ -225,6 +225,12 @@
);
ve.ui.commandRegistry.register(
new ve.ui.Command(
+ 'selectAll', 'content', 'selectAll',
+ { supportedSelections: ['linear', 'table'] }
+ )
+);
+ve.ui.commandRegistry.register(
+ new ve.ui.Command(
'comment', 'window', 'open',
{ args: ['comment'], supportedSelections: ['linear'] }
)
diff --git a/src/ui/ve.ui.TriggerRegistry.js b/src/ui/ve.ui.TriggerRegistry.js
index 8ff9a13..6530bbf 100644
--- a/src/ui/ve.ui.TriggerRegistry.js
+++ b/src/ui/ve.ui.TriggerRegistry.js
@@ -160,5 +160,8 @@
'preformatted', new ve.ui.Trigger ( 'ctrl+7' )
);
ve.ui.triggerRegistry.register(
+ 'selectAll', { mac: new ve.ui.Trigger( 'cmd+a' ), pc: new
ve.ui.Trigger( 'ctrl+a' ) }
+);
+ve.ui.triggerRegistry.register(
'pasteSpecial', { mac: new ve.ui.Trigger( 'cmd+shift+v' ), pc: new
ve.ui.Trigger ( 'ctrl+shift+v' ) }
);
--
To view, visit https://gerrit.wikimedia.org/r/172039
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ica731c596af9e6e3495298105ef1e79ba5cccd63
Gerrit-PatchSet: 1
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits