From daff6484cfec98d83027ec64e02dee03d480bfbb Mon Sep 17 00:00:00 2001 From: Philip Peitsch Date: Mon, 23 Jun 2014 17:50:40 +1000 Subject: [PATCH] Enabled direct text styling only if current selection is a text range Prevents the controller advertising things such as bold and underline are valid operations for an inline image (they are not!). --- programs/editor/widgets/simpleStyles.js | 9 --------- webodf/lib/gui/DirectFormattingController.js | 4 +++- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/programs/editor/widgets/simpleStyles.js b/programs/editor/widgets/simpleStyles.js index faa2bde7..2abe178d 100644 --- a/programs/editor/widgets/simpleStyles.js +++ b/programs/editor/widgets/simpleStyles.js @@ -167,16 +167,8 @@ define("webodf/editor/widgets/simpleStyles", [ }); } - function handleCursorMoved(cursor) { - if (directFormattingController.enabledFeatures().directTextStyling) { - var disabled = cursor.getSelectionType() === ops.OdtCursor.RegionSelection; - enableStyleButtons({ directTextStyling: !disabled }); - } - } - this.setEditorSession = function(session) { if (editorSession) { - editorSession.unsubscribe(EditorSession.signalCursorMoved, handleCursorMoved); directFormattingController.unsubscribe(gui.DirectFormattingController.textStylingChanged, updateStyleButtons); directFormattingController.unsubscribe(gui.DirectFormattingController.enabledChanged, enableStyleButtons); } @@ -186,7 +178,6 @@ define("webodf/editor/widgets/simpleStyles", [ if (editorSession) { directFormattingController = editorSession.sessionController.getDirectFormattingController(); - editorSession.subscribe(EditorSession.signalCursorMoved, handleCursorMoved); directFormattingController.subscribe(gui.DirectFormattingController.textStylingChanged, updateStyleButtons); directFormattingController.subscribe(gui.DirectFormattingController.enabledChanged, enableStyleButtons); diff --git a/webodf/lib/gui/DirectFormattingController.js b/webodf/lib/gui/DirectFormattingController.js index 7208a014..712192a6 100644 --- a/webodf/lib/gui/DirectFormattingController.js +++ b/webodf/lib/gui/DirectFormattingController.js @@ -148,7 +148,9 @@ gui.DirectFormattingController = function DirectFormattingController( } if (enabledFeatures.directTextStyling) { - enabledFeatures.directTextStyling = selectionContainsText; + enabledFeatures.directTextStyling = selectionContainsText + && cursor !== undefined // cursor might not be registered + && cursor.getSelectionType() === ops.OdtCursor.RangeSelection; } return /**@type{!gui.DirectFormattingController.SelectionInfo}*/({