From a726da638d4c28af6228908416971ae320431803 Mon Sep 17 00:00:00 2001 From: Peter Flynn Date: Thu, 25 Jul 2013 13:54:53 -0700 Subject: [PATCH] - Don't steal focus from editor when clicking toolbar buttons - Switch to safer path-parsing code (see adobe/brackets#4333) --- XMLPathFinder.js | 2 +- main.js | 22 ++++++++++++++++++---- package.json | 2 +- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/XMLPathFinder.js b/XMLPathFinder.js index 36fa208..d5f71ee 100644 --- a/XMLPathFinder.js +++ b/XMLPathFinder.js @@ -22,7 +22,7 @@ /*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50, regexp: true */ -/*global define, brackets, $, PathUtils, DOMParser */ +/*global define, brackets, $, DOMParser */ define(function (require, exports, module) { "use strict"; diff --git a/main.js b/main.js index 56dc6a0..20d35dc 100644 --- a/main.js +++ b/main.js @@ -22,7 +22,7 @@ /*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50, regexp: true */ -/*global define, brackets, $, PathUtils */ +/*global define, brackets, $ */ define(function (require, exports, module) { "use strict"; @@ -30,12 +30,18 @@ define(function (require, exports, module) { // Brackets modules var DocumentManager = brackets.getModule("document/DocumentManager"), EditorManager = brackets.getModule("editor/EditorManager"), + FileUtils = brackets.getModule("file/FileUtils"), ExtensionUtils = brackets.getModule("utils/ExtensionUtils"); // Extension's own modules var XMLPathFinder = require("XMLPathFinder"); + // TODO: + // - source->image linkage -- blink element in SVG (if Live Highlight is toggled on) + // - blink element's fill red/normal/red/normal a few times when cursor enters its text bounds + // - (during NON-EDIT cursor movement only... how to detect??) + /** * Preview panel that appears above the editor area. Lazily created, so may be null if never shown yet. * @type {?jQuery} @@ -169,7 +175,10 @@ define(function (require, exports, module) { $svgParent.removeClass("checker"); $svgParent.css("background-color", $elt.css("background-color")); } - }); + }) + .mousedown(function (event) { + event.preventDefault(); // don't steal focus + }); $(".svg-tb-button", $svgToolbar).click(function (event) { var zoomFactor = $(event.currentTarget).attr("data-zoomFactor"); @@ -179,7 +188,10 @@ define(function (require, exports, module) { currentState.zoomFactor *= zoomFactor; } updatePanel(EditorManager.getCurrentFullEditor()); - }); + }) + .mousedown(function (event) { + event.preventDefault(); // don't steal focus + }); } function createSVGPanel() { @@ -232,7 +244,9 @@ define(function (require, exports, module) { createSVGPanel(); // Inject panel into UI + // TODO: use PanelManager to create top panel, once possible $("#editor-holder").before($svgPanel); + } else if ($svgPanel.is(":hidden")) { $svgPanel.show(); } @@ -255,7 +269,7 @@ define(function (require, exports, module) { var newEditor = EditorManager.getCurrentFullEditor(); if (newEditor) { - var ext = PathUtils.filenameExtension(newEditor.document.file.fullPath); + var ext = FileUtils.getFilenameExtension(newEditor.document.file.fullPath); if (ext.toLowerCase() === ".svg") { showSVGPanel(newEditor); } else { diff --git a/package.json b/package.json index 3733b53..c53f2c3 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "title": "SVG Preview", "homepage": "https://github.com/peterflynn/svg-preview", "author": "Peter Flynn", - "version": "1.1.0", + "version": "1.1.1", "engines": { "brackets": ">=0.14" }, "description": "Live preview SVG files in an inline panel while you edit them." } \ No newline at end of file