├── README.md ├── package.json └── main.js /README.md: -------------------------------------------------------------------------------- 1 | Brackets Edit History 2 | ===================== 3 | 4 | A Brackets extension to navigate forward and backward among historical edit positions within a file. 5 | 6 | ## How to use 7 | Use the shortcut ```Alt -``` or the Navigate menu (Previous Edit Position) to jump to the last edit position, use ```Alt +``` to jump back. -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "brackets-edit-history", 3 | "title": "Brackets Edit History", 4 | "description": "Edit history extension for Brackets", 5 | "version": "0.1.2", 6 | "author" : "Ian Wehrman ", 7 | "homepage": "https://github.com/iwehrman/brackets-edit-history/", 8 | "bugs": "https://github.com/iwehrman/brackets-edit-history/issues", 9 | "repository" : { 10 | "type" : "git", 11 | "url" : "https://github.com/iwehrman/brackets-edit-history.git" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /main.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | 25 | /*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */ 26 | /*global define, brackets */ 27 | 28 | define(function (require, exports, module) { 29 | "use strict"; 30 | 31 | var EditorManager = brackets.getModule("editor/EditorManager"), 32 | CommandManager = brackets.getModule("command/CommandManager"), 33 | Menus = brackets.getModule("command/Menus"), 34 | AppInit = brackets.getModule("utils/AppInit"); 35 | 36 | var index = 1, 37 | previousLastChangePos = null; 38 | 39 | function nextEditPosition() { 40 | var editor = EditorManager.getFocusedEditor(); 41 | 42 | if (!editor) { 43 | return; 44 | } 45 | 46 | var cm = editor._codeMirror, 47 | doc = cm.doc, 48 | history = doc.getHistory(); 49 | 50 | if (history.done.length > 0) { 51 | var currentLastChangePos = history.done[history.done.length - 1].anchorBefore, 52 | cursor = cm.getCursor(), 53 | change = null; 54 | 55 | if (currentLastChangePos !== previousLastChangePos) { 56 | index = 1; 57 | } 58 | previousLastChangePos = currentLastChangePos; 59 | 60 | 61 | if (history.done.length >= index && index > 1) { 62 | do { 63 | change = history.done[history.done.length - (--index)].anchorBefore; 64 | } while (change.line === cursor.line && history.done.length >= index && index > 1); 65 | 66 | if (change !== null && change.line !== cursor.line) { 67 | cm.setCursor(change); 68 | } 69 | } 70 | 71 | } else { 72 | previousLastChangePos = null; 73 | } 74 | } 75 | 76 | function previousEditPosition() { 77 | var editor = EditorManager.getFocusedEditor(); 78 | 79 | if (!editor) { 80 | return; 81 | } 82 | 83 | var cm = editor._codeMirror, 84 | doc = cm.doc, 85 | history = doc.getHistory(); 86 | 87 | if (history.done.length > 0) { 88 | var currentLastChangePos = history.done[history.done.length - 1].anchorBefore, 89 | cursor = cm.getCursor(), 90 | change = null; 91 | 92 | if (currentLastChangePos !== previousLastChangePos) { 93 | index = 1; 94 | } 95 | previousLastChangePos = currentLastChangePos; 96 | 97 | if (history.done.length > index && index >= 0) { 98 | do { 99 | change = history.done[history.done.length - (++index)].anchorBefore; 100 | } while (change.line === cursor.line && history.done.length > index && index >= 0); 101 | 102 | if (change !== null && change.line !== cursor.line) { 103 | cm.setCursor(change); 104 | } 105 | } 106 | } else { 107 | previousLastChangePos = null; 108 | } 109 | } 110 | 111 | // load everything when brackets is done loading 112 | AppInit.appReady(function () { 113 | var NAVIGATE_EDIT_FORWARD = "navigate.edit.forward"; 114 | var NAVIGATE_EDIT_BACKWARD = "navigate.edit.backward"; 115 | 116 | var CMD_EDIT_FORWARD = "Next Edit Position"; 117 | var CMD_EDIT_BACKWARD = "Previous Edit Position"; 118 | 119 | CommandManager.register(CMD_EDIT_BACKWARD, NAVIGATE_EDIT_BACKWARD, previousEditPosition); 120 | CommandManager.register(CMD_EDIT_FORWARD, NAVIGATE_EDIT_FORWARD, nextEditPosition); 121 | 122 | var menu = Menus.getMenu(Menus.AppMenuBar.NAVIGATE_MENU); 123 | menu.addMenuItem(Menus.DIVIDER); 124 | menu.addMenuItem(NAVIGATE_EDIT_BACKWARD, "Alt--"); 125 | menu.addMenuItem(NAVIGATE_EDIT_FORWARD, "Alt-+"); 126 | }); 127 | 128 | }); 129 | --------------------------------------------------------------------------------