Skip to content

Commit 4b258db

Browse files
committed
fix: cannot uncomment markdown comment, fallbak to codemirror comment plugin
1 parent 7f2fa36 commit 4b258db

File tree

5 files changed

+35
-6
lines changed

5 files changed

+35
-6
lines changed

src/brackets.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ define(function (require, exports, module) {
6060
require("thirdparty/CodeMirror/addon/selection/active-line");
6161
require("thirdparty/CodeMirror/addon/selection/mark-selection");
6262
require("thirdparty/CodeMirror/addon/display/rulers");
63+
require("thirdparty/CodeMirror/addon/comment/comment");
6364
require("thirdparty/CodeMirror/keymap/sublime");
6465

6566
require("utils/EventDispatcher");

src/editor/Editor.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2219,6 +2219,18 @@ define(function (require, exports, module) {
22192219
this._codeMirror.clearGutter(gutterName);
22202220
};
22212221

2222+
/**
2223+
* Tries to uncomment the current selection, and if that fails, line-comments it.
2224+
* This is internal private api used by phoenix line toggle command
2225+
* @private
2226+
*/
2227+
Editor.prototype._toggleComment = function () {
2228+
const indentLineComment = Editor.getIndentLineComment(this.document.file.fullPath);
2229+
this._codeMirror.toggleComment({
2230+
indent: indentLineComment
2231+
});
2232+
};
2233+
22222234
/**
22232235
* Returns the list of gutters current registered on all editors.
22242236
* @return {!Array.<{name: string, priority: number}>}

src/editor/EditorCommandHandlers.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ define(function (require, exports, module) {
550550
});
551551

552552
// Uncomment - remove prefix and suffix.
553-
} else {
553+
} else if(prefixPos){
554554
// Find if the prefix and suffix are at the ch 0 and if they are the only thing in the line.
555555
// If both are found we assume that a complete line selection comment added new lines, so we remove them.
556556
var line = doc.getLine(prefixPos.line).trim(),
@@ -634,6 +634,11 @@ define(function (require, exports, module) {
634634
return _getBlockCommentPrefixSuffixEdit(editor, prefix, suffix, [], sel, lineSel.selectionsToTrack, command);
635635
}
636636

637+
function _languageHasCommentsDefined(editor) {
638+
const language = editor.document.getLanguage();
639+
return language && (language.hasLineCommentSyntax() || language.hasBlockCommentSyntax());
640+
}
641+
637642
/**
638643
* @private
639644
* Generates an array of edits for toggling line comments on the given selections.
@@ -684,6 +689,11 @@ define(function (require, exports, module) {
684689
return;
685690
}
686691

692+
if(!_languageHasCommentsDefined(editor)) {
693+
editor._toggleComment();
694+
return;
695+
}
696+
687697
editor.setSelections(editor.document.doMultipleEdits(_getLineCommentEdits(editor, editor.getSelections(), "line")));
688698
}
689699

@@ -697,6 +707,11 @@ define(function (require, exports, module) {
697707
return;
698708
}
699709

710+
if(!_languageHasCommentsDefined(editor)) {
711+
editor._toggleComment();
712+
return;
713+
}
714+
700715
var edits = [],
701716
lineCommentSels = [];
702717
_.each(editor.getSelections(), function (sel) {

src/editor/EditorManager.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,5 +825,8 @@ define(function (require, exports, module) {
825825
exports.focusEditor = focusEditor;
826826
exports.getCurrentlyViewedPath = getCurrentlyViewedPath;
827827
exports.setEditorHolder = setEditorHolder;
828-
window.ed = exports;
828+
829+
if(location.origin === "http://localhost:8000"){
830+
window.EditorManager = exports; // this is for quick editor queries during development in browser console
831+
}
829832
});

src/language/languages.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,15 +292,13 @@
292292

293293
"markdown": {
294294
"name": "Markdown",
295-
"mode": "markdown",
296-
"blockComment": ["<!--", "-->"]
295+
"mode": "markdown"
297296
},
298297

299298
"gfm": {
300299
"name": "Markdown (GitHub)",
301300
"mode": "gfm",
302-
"fileExtensions": ["md", "markdown", "mdown", "mkdn"],
303-
"blockComment": ["<!--", "-->"]
301+
"fileExtensions": ["md", "markdown", "mdown", "mkdn"]
304302
},
305303

306304
"yaml": {

0 commit comments

Comments
 (0)