diff --git a/data/environments.json b/data/environments.json index 4cd205df..adacb824 100644 --- a/data/environments.json +++ b/data/environments.json @@ -11,11 +11,11 @@ }, "enumerate": { "name": "enumerate", - "snippet": "\n\t\\item $0" + "snippet": "\n\t\\item $0\n\t\\item \n\t\\item " }, "itemize": { "name": "itemize", - "snippet": "\n\t\\item $0" + "snippet": "\n\t\\item $0\n\t\\item \n\t\\item " }, "math": { "name": "math" diff --git a/package.json b/package.json index fb39ae48..76952118 100644 --- a/package.json +++ b/package.json @@ -352,16 +352,6 @@ "mac": "cmd+alt+j", "command": "latex-toybox.synctex", "when": "editorTextFocus && editorLangId == 'latex' && !config.latex-toybox.bind.altKeymap.enabled && !virtualWorkspace" - }, - { - "key": "enter", - "command": "latex-toybox.onEnterKey", - "when": "latex-toybox:enabled && config.latex-toybox.bind.enter.key && editorTextFocus && (acceptSuggestionOnEnter && !suggestWidgetVisible || !acceptSuggestionOnEnter) && !editorReadonly && editorLangId =~ /^latex$|^latex-expl3$/ && (vim.active && vim.mode == 'Insert' || !vim.active)" - }, - { - "key": "alt+enter", - "command": "latex-toybox.onAltEnterKey", - "when": "latex-toybox:enabled && config.latex-toybox.bind.enter.key && editorTextFocus && (acceptSuggestionOnEnter && !suggestWidgetVisible || !acceptSuggestionOnEnter) && !editorReadonly && editorLangId =~ /^latex$|^latex-expl3$/" } ], "configurationDefaults": { @@ -1253,12 +1243,6 @@ "default": false, "markdownDescription": "Enable the LaTeX contextual menu. This menu is deactivated as it is available through the new LaTeX badge. Just set this variable to `true` to recover the menu." }, - "latex-toybox.bind.enter.key": { - "scope": "window", - "type": "boolean", - "default": true, - "markdownDescription": "Enable the automatic insertion of `\\item` on a newline when pressing `Enter` in a line starting in `\\item`." - }, "latex-toybox.bind.altKeymap.enabled": { "scope": "window", "type": "boolean", diff --git a/src/commander.ts b/src/commander.ts index 2988ea69..0f7d3d5a 100644 --- a/src/commander.ts +++ b/src/commander.ts @@ -272,63 +272,6 @@ export class Commander { return this.extension.envPair.gotoPair() } - /** - * If the current line starts with \item or \item[], do the same for - * the new line when hitting enter. - * Note that hitting enter on a line containing only \item or \item[] - * actually deletes the content of the line. - */ - onEnterKey(modifiers?: string) { - const editor = vscode.window.activeTextEditor - if (!editor) { - return - } - const configuration = vscode.workspace.getConfiguration('latex-toybox') - if (!configuration.get('bind.enter.key')) { - return vscode.commands.executeCommand('type', { source: 'keyboard', text: '\n' }) - } - if (modifiers === 'alt') { - return vscode.commands.executeCommand('editor.action.insertLineAfter') - } - - // Test if every cursor is at the end of a line starting with \item - const allCursorsOnItem = editor.selections.every((selection: vscode.Selection) => { - const cursorPos = selection.active - const line = editor.document.lineAt(cursorPos.line) - return /^\s*\\item/.test(line.text) && (line.text.substring(cursorPos.character).trim().length === 0) - }) - if (!allCursorsOnItem) { - return vscode.commands.executeCommand('type', { source: 'keyboard', text: '\n' }) - } - - return editor.edit(editBuilder => { - // If we arrive here, all the cursors are at the end of a line starting with `\s*\\item`. - // Yet, we keep the conditions for the sake of maintenance. - for (const selection of editor.selections) { - const cursorPos = selection.active - const line = editor.document.lineAt(cursorPos.line) - const indentation = line.text.substring(0, line.firstNonWhitespaceCharacterIndex) - - if (/^\s*\\item(\[\s*\])?\s*$/.test(line.text)) { - // The line is an empty \item or \item[] - const rangeToDelete = line.range.with(cursorPos.with(line.lineNumber, line.firstNonWhitespaceCharacterIndex), line.range.end) - editBuilder.delete(rangeToDelete) - } else if(/^\s*\\item\[[^[\]]*\]/.test(line.text)) { - // The line starts with \item[blabla] or \item[] blabla - const itemString = `\n${indentation}\\item[] ` - editBuilder.insert(cursorPos, itemString) - } else if(/^\s*\\item\s*[^\s]+.*$/.test(line.text)) { - // The line starts with \item blabla - const itemString = `\n${indentation}\\item ` - editBuilder.insert(cursorPos, itemString) - } else { - // If we do not know what to do, insert a newline and indent using the current indentation - editBuilder.insert(cursorPos, `\n${indentation}`) - } - } - }) - } - /** * Shift the level sectioning in the selection by one (up or down) * @param change diff --git a/src/main.ts b/src/main.ts index 6fcb1830..b1b07c31 100644 --- a/src/main.ts +++ b/src/main.ts @@ -68,8 +68,6 @@ function registerLatexToyboxCommands( vscode.commands.registerCommand('latex-toybox.compilerlog', () => extension.commander.log('compiler')), vscode.commands.registerCommand('latex-toybox.goto-section', (filePath: string, lineNumber: number) => extension.commander.gotoSection(filePath, lineNumber)), vscode.commands.registerCommand('latex-toybox.navigate-envpair', () => extension.commander.navigateToEnvPair()), - vscode.commands.registerCommand('latex-toybox.onEnterKey', () => extension.commander.onEnterKey()), - vscode.commands.registerCommand('latex-toybox.onAltEnterKey', () => extension.commander.onEnterKey('alt')), vscode.commands.registerCommand('latex-toybox.revealOutputDir', () => extension.commander.revealOutputDir()), vscode.commands.registerCommand('latex-toybox.promote-sectioning', () => extension.commander.shiftSectioningLevel('promote')),