fix/ Script execution is prevented by line comments (#3462)

* refactor: simplify mode settings and update comment toggle functionality
---------

Co-authored-by: Anoop M D <anoop.md1421@gmail.com>
This commit is contained in:
Sanjai Kumar 2024-11-20 18:14:37 +05:30 committed by GitHub
parent d92dd46d4e
commit 84095a4183
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -190,32 +190,8 @@ export default class CodeEditor extends React.Component {
'Cmd-Y': 'foldAll', 'Cmd-Y': 'foldAll',
'Ctrl-I': 'unfoldAll', 'Ctrl-I': 'unfoldAll',
'Cmd-I': 'unfoldAll', 'Cmd-I': 'unfoldAll',
'Cmd-/': (cm) => { 'Ctrl-/': 'toggleComment',
// comment/uncomment every selected line(s) 'Cmd-/': 'toggleComment'
const selections = cm.listSelections();
selections.forEach((range) => {
for (let i = range.from().line; i <= range.to().line; i++) {
const selectedLine = cm.getLine(i);
// if commented line, remove comment
if (selectedLine.trim().startsWith('//')) {
cm.replaceRange(
selectedLine.replace(/^(\s*)\/\/\s?/, '$1'),
{ line: i, ch: 0 },
{ line: i, ch: selectedLine.length }
);
continue;
}
// otherwise add comment
cm.replaceRange(
selectedLine.search(/\S|$/) >= TAB_SIZE
? ' '.repeat(TAB_SIZE) + '// ' + selectedLine.trim()
: '// ' + selectedLine,
{ line: i, ch: 0 },
{ line: i, ch: selectedLine.length }
);
}
});
}
}, },
foldOptions: { foldOptions: {
widget: (from, to) => { widget: (from, to) => {