Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit 1eba0ae

Browse files
committed
Added nls Strings description for code-folding feature for making selections foldable.
Minor modification to CodeMirror helper fold.auto - a range is now only returned if the number of lines spanned by the range is at least the minimum fold size set in the prefs. This has implications for global helpers.
1 parent f601475 commit 1eba0ae

5 files changed

Lines changed: 25 additions & 8 deletions

File tree

src/extensions/default/CodeFolding/Prefs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ define(function (require, exports, module) {
3737
prefs.definePreference("maxFoldLevel", "number", 2,
3838
{name: MAX_FOLD_LEVEL, description: Strings.DESCRIPTION_CODE_FOLDING_MAX_FOLD_LEVEL});
3939
prefs.definePreference("makeSelectionsFoldable", "boolean", true,
40-
{name: MAKE_SELECTIONS_FOLDABLE, description: MAKE_SELECTIONS_FOLDABLE});
40+
{name: MAKE_SELECTIONS_FOLDABLE, description: Strings.DESCRIPTION_CODE_FOLDING_MAKE_SELECTIONS_FOLDABLE});
4141

4242
PreferencesManager.stateManager.definePreference(FOLDS_PREF_KEY, "object", {});
4343

src/extensions/default/CodeFolding/foldhelpers/foldcode.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,16 +251,16 @@ define(function (require, exports, module) {
251251
* @param {number} start the current position in the document
252252
*/
253253
CodeMirror.registerHelper("fold", "auto", function (cm, start) {
254-
var helpers = cm.getHelpers(start, "fold"), i, cur;
254+
var helpers = cm.getHelpers(start, "fold"), i, range;
255255
//ensure mode helper is loaded if there is one
256256
var mode = cm.getMode().name;
257257
var modeHelper = CodeMirror.fold[mode];
258258
if (modeHelper && helpers.indexOf(modeHelper) < 0) {
259259
helpers.push(modeHelper);
260260
}
261261
for (i = 0; i < helpers.length; i++) {
262-
cur = helpers[i](cm, start);
263-
if (cur) { return cur; }
262+
range = helpers[i](cm, start);
263+
if (range && range.to.line - range.from.line >= prefs.getSetting("minFoldSize")) { return range; }
264264
}
265265
});
266266
}

src/extensions/default/CodeFolding/foldhelpers/foldgutter.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,21 @@ define(function (require, exports, module) {
317317
}, 400);
318318
}
319319

320+
/**
321+
* Triggered when the cursor moves in the editor and used to detect text selection changes
322+
* in the editor.
323+
* @param {!CodeMirror} cm the CodeMirror instance for the active editor
324+
*/
325+
function onCursorActivity(cm) {
326+
var state = cm.state.foldGutter;
327+
window.clearTimeout(state.changeUpdate);
328+
state.changeUpdate = window.setTimeout(function () {
329+
var from = cm.getCursor("from"),
330+
to = cm.getCursor("to");
331+
updateInViewport(cm, from.line, to.line);
332+
}, 400);
333+
}
334+
320335
/**
321336
* Triggered when a code segment is folded.
322337
* @param {!CodeMirror} cm the CodeMirror instance for the active editor
@@ -356,7 +371,7 @@ define(function (require, exports, module) {
356371
cm.off("gutterClick", old.onGutterClick);
357372
cm.off("change", onChange);
358373
cm.off("viewportChange", onViewportChange);
359-
cm.off("cursorActivity", onViewportChange);
374+
cm.off("cursorActivity", onCursorActivity);
360375

361376
cm.off("fold", onFold);
362377
cm.off("unfold", onUnFold);
@@ -368,7 +383,7 @@ define(function (require, exports, module) {
368383
cm.on("gutterClick", val.onGutterClick);
369384
cm.on("change", onChange);
370385
cm.on("viewportChange", onViewportChange);
371-
cm.on("cursorActivity", onViewportChange);
386+
cm.on("cursorActivity", onCursorActivity);
372387
cm.on("fold", onFold);
373388
cm.on("unfold", onUnFold);
374389
cm.on("swapDoc", updateInViewport);

src/extensions/default/CodeFolding/main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ define(function (require, exports, module) {
369369
KeyBindingManager.addBinding(COLLAPSE, collapseKey);
370370
KeyBindingManager.addBinding(EXPAND, expandKey);
371371

372+
372373
// Add gutters & restore saved expand/collapse state in all currently open editors
373374
Editor.forEveryEditor(function (editor) {
374375
enableFoldingInEditor(editor);

src/nls/root/strings.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ define({
600600
"CMD_RESTART_NODE" : "Restart Node",
601601
"CMD_SHOW_ERRORS_IN_STATUS_BAR" : "Show Errors in Status Bar",
602602
"CMD_OPEN_BRACKETS_SOURCE" : "Open {APP_NAME} Source",
603-
603+
604604
"CREATING_LAUNCH_SCRIPT_TITLE" : "{APP_NAME} Command Line Shortcut",
605605
"ERROR_CREATING_LAUNCH_SCRIPT" : "An error occurred while installing the command line shortcut. Please try <a href='https://github.com/adobe/brackets/wiki/Command-Line-Arguments#troubleshooting'>these troubleshooting suggestions</a>.<br/><br/>Reason: {0}",
606606
"ERROR_CLTOOLS_RMFAILED" : "Unable to remove existing <code>/usr/local/bin/brackets</code> symlink.",
@@ -664,7 +664,7 @@ define({
664664
"EXPAND_ALL" : "Expand All",
665665
"COLLAPSE_CURRENT" : "Collapse Current",
666666
"EXPAND_CURRENT" : "Expand Current",
667-
667+
668668
// Descriptions of core preferences
669669
"DESCRIPTION_CLOSE_BRACKETS" : "true to automatically close braces, brackets and parentheses",
670670
"DESCRIPTION_CLOSE_OTHERS_ABOVE" : "false to remove the \"Close Others Above\" from the Working Files context menu",
@@ -681,6 +681,7 @@ define({
681681
"DESCRIPTION_CODE_FOLDING_MAX_FOLD_LEVEL" : "Limits how many levels deep Collapse All applies",
682682
"DESCRIPTION_CODE_FOLDING_MIN_FOLD_SIZE" : "Minimum lines before a collapsible section icon appears",
683683
"DESCRIPTION_CODE_FOLDING_SAVE_FOLD_STATES" : "true to remember collapsed sections if you close and reopen a file or project",
684+
"DESCRIPTION_CODE_FOLDING_MAKE_SELECTIONS_FOLDABLE": "true to enable code folding on selected text in the editor",
684685
"DESCRIPTION_ATTR_HINTS" : "Enable/disable HTML attribute hints",
685686
"DESCRIPTION_CSS_PROP_HINTS" : "Enable/disable CSS/LESS/SCSS property hints",
686687
"DESCRIPTION_JS_HINTS" : "Enable/disable JavaScript code hints",

0 commit comments

Comments
 (0)