export function fetchSelectItem(direction: string): void { let editor = vscode.window.activeTextEditor; if (!validate()) { return; } let nextItem; let prevItem; if (isStyleSheet(editor.document.languageId)) { nextItem = nextItemStylesheet; prevItem = prevItemStylesheet; } else { nextItem = nextItemHTML; prevItem = prevItemHTML; } let rootNode = parse(editor.document); if (!rootNode) { return; } let newSelections: vscode.Selection[] = []; editor.selections.forEach(selection => { const selectionStart = selection.isReversed ? selection.active : selection.anchor; const selectionEnd = selection.isReversed ? selection.anchor : selection.active; let updatedSelection = direction === 'next' ? nextItem(selectionStart, selectionEnd, editor, rootNode) : prevItem(selectionStart, selectionEnd, editor, rootNode); newSelections.push(updatedSelection ? updatedSelection : selection); }); editor.selections = newSelections; editor.revealRange(editor.selections[editor.selections.length - 1]); }
export function toggleComment() { let editor = vscode.window.activeTextEditor; if (!editor) { vscode.window.showInformationMessage('No editor is active'); return; } let toggleCommentInternal; let startComment; let endComment; if (isStyleSheet(editor.document.languageId)) { toggleCommentInternal = toggleCommentStylesheet; startComment = startCommentStylesheet; endComment = endCommentStylesheet; } else { toggleCommentInternal = toggleCommentHTML; startComment = startCommentHTML; endComment = endCommentHTML; } let rootNode = parseDocument(editor.document); if (!rootNode) { return; } editor.edit(editBuilder => { editor.selections.reverse().forEach(selection => { let [rangesToUnComment, rangeToComment] = toggleCommentInternal(editor.document, selection, rootNode); rangesToUnComment.forEach((rangeToUnComment: vscode.Range) => { editBuilder.delete(new vscode.Range(rangeToUnComment.start, rangeToUnComment.start.translate(0, startComment.length))); editBuilder.delete(new vscode.Range(rangeToUnComment.end.translate(0, -endComment.length), rangeToUnComment.end)); }); if (rangeToComment) { editBuilder.insert(rangeToComment.start, startComment); editBuilder.insert(rangeToComment.end, endComment); } }); }); }