From 21ee17a1921089fc79ff5fa8b8f837a5419d88a2 Mon Sep 17 00:00:00 2001 From: Rob Moen Date: Wed, 6 Jun 2012 11:51:19 -0700 Subject: [PATCH] Fix up some tools to not break on selection, added some test selection stuff to sandbox Change-Id: Ic97144e634111c489507814c6634c66831726191 --- modules/sandbox/sandbox.js | 8 +++++++- modules/ve2/ui/tools/ve.ui.FormatDropdownTool.js | 4 ++-- modules/ve2/ui/tools/ve.ui.IndentationButtonTool.js | 5 ++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/modules/sandbox/sandbox.js b/modules/sandbox/sandbox.js index 1b49f32acf..2af83da829 100644 --- a/modules/sandbox/sandbox.js +++ b/modules/sandbox/sandbox.js @@ -646,7 +646,13 @@ $(document).ready( function() { var sandboxEditor = new ve.Surface( '#content', HTML[0], options ), surfaceModel = sandboxEditor.getSurfaceModel(), documentModel = sandboxEditor.getDocumentModel(), - parent = sandboxEditor.getParent(); + parent = sandboxEditor.getParent(), + view = sandboxEditor.view; + + /* Rob's test selection stuff */ + /*surfaceModel.setSelection( new ve.Range(0, documentModel.getData().length ) ); + view.showSelection ( surfaceModel.getSelection() ); + console.log (surfaceModel.getSelection().getLength());*/ /* Sandbox Warning Message */ diff --git a/modules/ve2/ui/tools/ve.ui.FormatDropdownTool.js b/modules/ve2/ui/tools/ve.ui.FormatDropdownTool.js index a2051b2f58..19fcc2c5f1 100644 --- a/modules/ve2/ui/tools/ve.ui.FormatDropdownTool.js +++ b/modules/ve2/ui/tools/ve.ui.FormatDropdownTool.js @@ -86,8 +86,8 @@ ve.FormatDropdownTool.prototype.updateState = function( annotations, nodes ) { 'attributes': nodes[0].attributes }; // Look for mismatches, in which case format should be null - for ( i = 1; i < nodes[0].children.length; i++ ) { - if ( format.type != nodes[0].children[i].getElementType() || + for ( i = 1; i < nodes.length; i++ ) { + if ( format.type != nodes[i].getElementType() || !ve.compareObjects( format.attributes, nodes.children[i].element.attributes ) ) { format = null; break; diff --git a/modules/ve2/ui/tools/ve.ui.IndentationButtonTool.js b/modules/ve2/ui/tools/ve.ui.IndentationButtonTool.js index eaa43454ab..29b18cc263 100644 --- a/modules/ve2/ui/tools/ve.ui.IndentationButtonTool.js +++ b/modules/ve2/ui/tools/ve.ui.IndentationButtonTool.js @@ -78,7 +78,10 @@ ve.ui.IndentationButtonTool.prototype.outdent = function( listItems ) { ve.ui.IndentationButtonTool.prototype.updateState = function( annotations, nodes ) { function areListItems( nodes ) { for( var i = 0; i < nodes.length; i++ ) { - if ( nodes[i].getParent().getElementType() !== 'listItem' ) { + if ( + nodes[i].parent !== null && + nodes[i].getParent().getElementType() !== 'listItem' ) + { return false; } }