Esanders has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/347901 )

Change subject: Introduce single-line mode for surfaces
......................................................................

Introduce single-line mode for surfaces

Or rather multi-line, defaulted to true.

For now this blocks the creation of newlines using <enter> or
via paste.

There are other ways to trigger complex creation that will need
to be addressed later, possibly at the transaction level:

* Pasting objects (e.g. HTML files)
* Sequences (e.g. '* ')
* Commands (no real-world examples)

Change-Id: I31fce3cc9ac6f7c12ec916b364b91cead2b4e6c9
---
M src/ce/keydownhandlers/ve.ce.LinearEnterKeyDownHandler.js
M src/ce/keydownhandlers/ve.ce.TableArrowKeyDownHandler.js
M src/ce/ve.ce.Surface.js
M src/dm/lineardata/ve.dm.ElementLinearData.js
M src/ui/ve.ui.Surface.js
M src/ui/widgets/ve.ui.TargetWidget.js
6 files changed, 39 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor 
refs/changes/01/347901/1

diff --git a/src/ce/keydownhandlers/ve.ce.LinearEnterKeyDownHandler.js 
b/src/ce/keydownhandlers/ve.ce.LinearEnterKeyDownHandler.js
index fa8a64d..7d05f16 100644
--- a/src/ce/keydownhandlers/ve.ce.LinearEnterKeyDownHandler.js
+++ b/src/ce/keydownhandlers/ve.ce.LinearEnterKeyDownHandler.js
@@ -49,6 +49,10 @@
 
        e.preventDefault();
 
+       if ( !surface.getSurface().isMultiline() ) {
+               return true;
+       }
+
        if ( ( e.ctrlKey || e.metaKey ) && surface.getSurface().getInDialog() ) 
{
                // We're inside a dialog. OOUI behavior is to close+submit a 
dialog if
                // ctrl/cmd+enter is pressed. If this dialog is going to close, 
we
diff --git a/src/ce/keydownhandlers/ve.ce.TableArrowKeyDownHandler.js 
b/src/ce/keydownhandlers/ve.ce.TableArrowKeyDownHandler.js
index 84cbcd2..e82a26a 100644
--- a/src/ce/keydownhandlers/ve.ce.TableArrowKeyDownHandler.js
+++ b/src/ce/keydownhandlers/ve.ce.TableArrowKeyDownHandler.js
@@ -89,6 +89,7 @@
        e.preventDefault();
 
        this.moveTableSelection( surface, rowOffset, colOffset, checkDir, 
expand, wrap );
+       return true;
 };
 
 /**
diff --git a/src/ce/ve.ce.Surface.js b/src/ce/ve.ce.Surface.js
index 8d04250..5620fae 100644
--- a/src/ce/ve.ce.Surface.js
+++ b/src/ce/ve.ce.Surface.js
@@ -1100,7 +1100,10 @@
 
        } else {
                // External drop
-               this.handleDataTransfer( dataTransfer, false, targetFragment );
+               // TODO: Support sanitized drop on single line surfaces
+               if ( this.getSurface().isMultiline() ) {
+                       this.handleDataTransfer( dataTransfer, false, 
targetFragment );
+               }
        }
        this.endRelocation();
 };
diff --git a/src/dm/lineardata/ve.dm.ElementLinearData.js 
b/src/dm/lineardata/ve.dm.ElementLinearData.js
index cc96094..c0c6014 100644
--- a/src/dm/lineardata/ve.dm.ElementLinearData.js
+++ b/src/dm/lineardata/ve.dm.ElementLinearData.js
@@ -1100,6 +1100,7 @@
  * @param {boolean} [rules.preserveHtmlWhitespace] Preserve non-semantic HTML 
whitespace
  * @param {boolean} [rules.nodeSanitization] Apply per-type node sanitizations 
via ve.dm.Node#sanitize
  * @param {boolean} [rules.keepEmptyContentBranches] Preserve empty content 
branch nodes
+ * @param {boolean} [rules.singleLine] Don't allow more that one 
ContentBranchNode
  */
 ve.dm.ElementLinearData.prototype.sanitize = function ( rules ) {
        var i, len, annotations, emptySet, setToRemove, type, oldHash, newHash,
@@ -1228,6 +1229,16 @@
                                }
                        }
 
+                       if ( canContainContent && !isOpen && rules.singleLine ) 
{
+                               i++;
+                               start = i;
+                               while ( i < len && !( this.isOpenElementData( i 
) && this.getType( i ) === 'internalList' ) ) {
+                                       i++;
+                               }
+                               this.splice( start, i - start );
+                               break;
+                       }
+
                        // Store the current contentElement for splitting
                        if ( canContainContent ) {
                                contentElement = isOpen ? this.getData( i ) : 
null;
diff --git a/src/ui/ve.ui.Surface.js b/src/ui/ve.ui.Surface.js
index e25a74b..4c89bee 100644
--- a/src/ui/ve.ui.Surface.js
+++ b/src/ui/ve.ui.Surface.js
@@ -22,6 +22,7 @@
  * @cfg {string[]|null} [includeCommands] List of commands to include, null 
for all registered commands
  * @cfg {string[]} [excludeCommands] List of commands to exclude
  * @cfg {Object} [importRules] Import rules
+ * @cfg {boolean} [multiline=true] Multi-line surface
  * @cfg {string} [placeholder] Placeholder text to display when the surface is 
empty
  * @cfg {string} [inDialog] The name of the dialog this surface is in
  */
@@ -69,6 +70,7 @@
        this.view = this.createView( this.model );
        this.dialogs = this.createDialogWindowManager();
        this.importRules = config.importRules || {};
+       this.multiline = config.multiline !== false;
        this.context = this.createContext();
        this.progresses = [];
        this.showProgressDebounced = ve.debounce( this.showProgress.bind( this 
) );
@@ -750,7 +752,20 @@
  * @return {Object} Import rules
  */
 ve.ui.Surface.prototype.getImportRules = function () {
-       return this.importRules;
+       var singleLine = { singleLine: !this.multiline };
+       return {
+               all: ve.extendObject( {}, this.importRules.all, singleLine ),
+               external: ve.extendObject( {}, this.importRules.external, 
singleLine )
+       };
+};
+
+/**
+ * Check if the surface is multi-line
+ *
+ * @return {boolean} Surface is multi-line
+ */
+ve.ui.Surface.prototype.isMultiline = function () {
+       return this.multiline;
 };
 
 /**
diff --git a/src/ui/widgets/ve.ui.TargetWidget.js 
b/src/ui/widgets/ve.ui.TargetWidget.js
index 34b6e89..e3436ac 100644
--- a/src/ui/widgets/ve.ui.TargetWidget.js
+++ b/src/ui/widgets/ve.ui.TargetWidget.js
@@ -21,6 +21,7 @@
  * @cfg {string[]|null} [includeCommands] List of commands to include, null 
for all registered commands
  * @cfg {string[]} [excludeCommands] List of commands to exclude
  * @cfg {Object} [importRules] Import rules
+ * @cfg {boolean} [multiline] Multi-line surface
  * @cfg {string} [inDialog] The name of the dialog this surface widget is in
  */
 ve.ui.TargetWidget = function VeUiTargetWidget( config ) {
@@ -38,6 +39,7 @@
        this.tools = config.tools;
        this.includeCommands = config.includeCommands;
        this.excludeCommands = config.excludeCommands;
+       this.multiline = config.multiline !== false;
        this.importRules = config.importRules;
        this.inDialog = config.inDialog;
        // TODO: Support source widgets
@@ -94,6 +96,7 @@
                includeCommands: this.includeCommands,
                excludeCommands: this.excludeCommands,
                importRules: this.importRules,
+               multiline: this.multiline,
                inDialog: this.inDialog
        } );
 

-- 
To view, visit https://gerrit.wikimedia.org/r/347901
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I31fce3cc9ac6f7c12ec916b364b91cead2b4e6c9
Gerrit-PatchSet: 1
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <esand...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to