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

Commit

Permalink
Added nls Strings description for code-folding feature for making sel…
Browse files Browse the repository at this point in the history
…ections 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.
  • Loading branch information
thehogfather committed Aug 5, 2015
1 parent f601475 commit 1eba0ae
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/extensions/default/CodeFolding/Prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ define(function (require, exports, module) {
prefs.definePreference("maxFoldLevel", "number", 2,
{name: MAX_FOLD_LEVEL, description: Strings.DESCRIPTION_CODE_FOLDING_MAX_FOLD_LEVEL});
prefs.definePreference("makeSelectionsFoldable", "boolean", true,
{name: MAKE_SELECTIONS_FOLDABLE, description: MAKE_SELECTIONS_FOLDABLE});
{name: MAKE_SELECTIONS_FOLDABLE, description: Strings.DESCRIPTION_CODE_FOLDING_MAKE_SELECTIONS_FOLDABLE});

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

Expand Down
6 changes: 3 additions & 3 deletions src/extensions/default/CodeFolding/foldhelpers/foldcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,16 +251,16 @@ define(function (require, exports, module) {
* @param {number} start the current position in the document
*/
CodeMirror.registerHelper("fold", "auto", function (cm, start) {
var helpers = cm.getHelpers(start, "fold"), i, cur;
var helpers = cm.getHelpers(start, "fold"), i, range;
//ensure mode helper is loaded if there is one
var mode = cm.getMode().name;
var modeHelper = CodeMirror.fold[mode];
if (modeHelper && helpers.indexOf(modeHelper) < 0) {
helpers.push(modeHelper);
}
for (i = 0; i < helpers.length; i++) {
cur = helpers[i](cm, start);
if (cur) { return cur; }
range = helpers[i](cm, start);
if (range && range.to.line - range.from.line >= prefs.getSetting("minFoldSize")) { return range; }
}
});
}
Expand Down
19 changes: 17 additions & 2 deletions src/extensions/default/CodeFolding/foldhelpers/foldgutter.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,21 @@ define(function (require, exports, module) {
}, 400);
}

/**
* Triggered when the cursor moves in the editor and used to detect text selection changes
* in the editor.
* @param {!CodeMirror} cm the CodeMirror instance for the active editor
*/
function onCursorActivity(cm) {
var state = cm.state.foldGutter;
window.clearTimeout(state.changeUpdate);
state.changeUpdate = window.setTimeout(function () {
var from = cm.getCursor("from"),
to = cm.getCursor("to");
updateInViewport(cm, from.line, to.line);
}, 400);
}

/**
* Triggered when a code segment is folded.
* @param {!CodeMirror} cm the CodeMirror instance for the active editor
Expand Down Expand Up @@ -356,7 +371,7 @@ define(function (require, exports, module) {
cm.off("gutterClick", old.onGutterClick);
cm.off("change", onChange);
cm.off("viewportChange", onViewportChange);
cm.off("cursorActivity", onViewportChange);
cm.off("cursorActivity", onCursorActivity);

cm.off("fold", onFold);
cm.off("unfold", onUnFold);
Expand All @@ -368,7 +383,7 @@ define(function (require, exports, module) {
cm.on("gutterClick", val.onGutterClick);
cm.on("change", onChange);
cm.on("viewportChange", onViewportChange);
cm.on("cursorActivity", onViewportChange);
cm.on("cursorActivity", onCursorActivity);
cm.on("fold", onFold);
cm.on("unfold", onUnFold);
cm.on("swapDoc", updateInViewport);
Expand Down
1 change: 1 addition & 0 deletions src/extensions/default/CodeFolding/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ define(function (require, exports, module) {
KeyBindingManager.addBinding(COLLAPSE, collapseKey);
KeyBindingManager.addBinding(EXPAND, expandKey);


// Add gutters & restore saved expand/collapse state in all currently open editors
Editor.forEveryEditor(function (editor) {
enableFoldingInEditor(editor);
Expand Down
5 changes: 3 additions & 2 deletions src/nls/root/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ define({
"CMD_RESTART_NODE" : "Restart Node",
"CMD_SHOW_ERRORS_IN_STATUS_BAR" : "Show Errors in Status Bar",
"CMD_OPEN_BRACKETS_SOURCE" : "Open {APP_NAME} Source",

"CREATING_LAUNCH_SCRIPT_TITLE" : "{APP_NAME} Command Line Shortcut",
"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}",
"ERROR_CLTOOLS_RMFAILED" : "Unable to remove existing <code>/usr/local/bin/brackets</code> symlink.",
Expand Down Expand Up @@ -664,7 +664,7 @@ define({
"EXPAND_ALL" : "Expand All",
"COLLAPSE_CURRENT" : "Collapse Current",
"EXPAND_CURRENT" : "Expand Current",

// Descriptions of core preferences
"DESCRIPTION_CLOSE_BRACKETS" : "true to automatically close braces, brackets and parentheses",
"DESCRIPTION_CLOSE_OTHERS_ABOVE" : "false to remove the \"Close Others Above\" from the Working Files context menu",
Expand All @@ -681,6 +681,7 @@ define({
"DESCRIPTION_CODE_FOLDING_MAX_FOLD_LEVEL" : "Limits how many levels deep Collapse All applies",
"DESCRIPTION_CODE_FOLDING_MIN_FOLD_SIZE" : "Minimum lines before a collapsible section icon appears",
"DESCRIPTION_CODE_FOLDING_SAVE_FOLD_STATES" : "true to remember collapsed sections if you close and reopen a file or project",
"DESCRIPTION_CODE_FOLDING_MAKE_SELECTIONS_FOLDABLE": "true to enable code folding on selected text in the editor",
"DESCRIPTION_ATTR_HINTS" : "Enable/disable HTML attribute hints",
"DESCRIPTION_CSS_PROP_HINTS" : "Enable/disable CSS/LESS/SCSS property hints",
"DESCRIPTION_JS_HINTS" : "Enable/disable JavaScript code hints",
Expand Down

0 comments on commit 1eba0ae

Please sign in to comment.