diff --git a/README.md b/README.md index 6fae43d..2f1a2be 100644 --- a/README.md +++ b/README.md @@ -12,12 +12,14 @@ Everyscrub is an extension for [Brackets](https://github.com/adobe/brackets/), a To use Everyscrub: -1. [Download the ZIP](https://github.com/peterflynn/everyscrub/downloads) and unzip it; or clone this repo +1. [Download the ZIP](https://github.com/peterflynn/everyscrub/archive/master.zip) and unzip it; or clone this repo 2. Open your extensions folder: _Help > Show Extensions Folder_ 3. Place the folder so the structure is: `extensions/user/everyscrub/main.js` 4. Restart Brackets! -License -======= -MIT-licensed -- see _main.js_ for details. \ No newline at end of file +### License +MIT-licensed -- see `main.js` for details. + +### Compatibility +Brackets Sprint 14 or newer (or any version of Adobe Edge Code). Undo functionality is improved when running in Brackets Sprint 20 or newer. \ No newline at end of file diff --git a/main.js b/main.js index 0044562..7ceb764 100644 --- a/main.js +++ b/main.js @@ -40,6 +40,8 @@ define(function (require, exports, module) { return (val < 0 ? 0 : (val > max ? max : val)); } + var uniqueNum = 0; // used to ensure unique undo batching per drag + // Scrubbing a single number (with optional suffix) function SimpleNumberScrub(origStringValue, prefix, suffix) { @@ -94,7 +96,7 @@ define(function (require, exports, module) { // Colors in LESS are type number return token.string; } else if (token.className === "string") { - // Token type string may contain a number, e.g. in HTML or SVG code + // Token type string may contain a number in the attrs of XML-like modes (e.g. HTML or SVG) return token.string; } } @@ -156,11 +158,16 @@ define(function (require, exports, module) { }; function parseForScrub(token) { - return ( + var initialState = ( Color3Scrub.parse(token) || Color6Scrub.parse(token) || SimpleNumberScrub.parse(token) ); + if (initialState) { + // in Sprint 20 (CMv3), this ensures the entire drag (or consecutive nudges) is undone atomically; ignored in earlier builds + initialState.origin = "*everyscrub" + (++uniqueNum); + } + return initialState; } @@ -182,7 +189,7 @@ define(function (require, exports, module) { if (newVal !== lastValue) { lastValue = newVal; - editor._codeMirror.replaceRange(newVal, lastRange.start, lastRange.end); + editor._codeMirror.replaceRange(newVal, lastRange.start, lastRange.end, scrubState.origin); lastRange.end.ch = lastRange.start.ch + newVal.length; editor.setSelection(lastRange.start, lastRange.end); } @@ -198,8 +205,9 @@ define(function (require, exports, module) { // ------------------- X = coordsChar().ch, interpreted as a char pos // | | *I X | I = coordsChar().ch, interpreted as a cursor pos / insertion point // ------------------- - var pos = editor._codeMirror.coordsChar({x: event.pageX, y: event.pageY}); - var chLeftEdge = editor._codeMirror.charCoords(pos).x; + var pos = editor._codeMirror.coordsChar({x: event.pageX, y: event.pageY, left: event.pageX, top: event.pageY}); // x/y for CMv2; left/top for v3 + var charBounds = editor._codeMirror.charCoords(pos); + var chLeftEdge = (charBounds.x !== undefined) ? charBounds.x : charBounds.left; // x for CMv2; left for CMv3 var mousedownCh = (chLeftEdge <= event.pageX) ? pos.ch : pos.ch - 1; // ch+1 because getTokenAt() returns the token *ending* at cursor pos 'ch' (char at 'ch' is NOT part of the token) @@ -305,7 +313,7 @@ define(function (require, exports, module) { if (scrubState) { var newVal = scrubState.update(lastNudge.delta); var tokenRange = {start: {line: cursorPos.line, ch: token.start}, end: {line: cursorPos.line, ch: token.end}}; - editor._codeMirror.replaceRange(newVal, tokenRange.start, tokenRange.end); + editor._codeMirror.replaceRange(newVal, tokenRange.start, tokenRange.end, scrubState.origin); lastNudge.lastText = newVal; tokenRange.end.ch = tokenRange.start.ch + newVal.length;