You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This extension is brilliant!
I've edited locally insertFootnote.js with the following code to mimic the behaviour of this atom extension, which generates a random hash for each footnote and "removes the hassle of having to track footnote numbering through the file or between collaborators".
It works well. Do you think this could be a worthwhile option to add to your extension?
function nextLine(position) {
return new vscode.Position(position.line + 1, 0);
}
// Function to generate a random hash of 6 letters (uppercase) and digits
function generateRandomHash(length = 6) {
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
let result = '';
for (let i = 0; i < length; i++) {
result += chars.charAt(Math.floor(Math.random() * chars.length));
}
return result;
}
function insertFootnote({ footnoteName } = {}) {
return __awaiter(this, void 0, void 0, function* () {
const editor = vscode.window.activeTextEditor;
if (!editor) {
return;
}
let text;
const shouldInsertFootnoteRef = !footnoteName;
if (shouldInsertFootnoteRef) {
const refMatches = utils_1.matchAll(utils_1.footnoteRefRegex, editor.document.getText());
// Using a random hash as the default footnote name if not provided
const defaultFootnoteName = generateRandomHash();
footnoteName =
(yield vscode.window.showInputBox({
prompt: 'Footnote name (no space or tab)',
placeHolder: 'Optional: Specific footnote name',
value: defaultFootnoteName, // Setting the default value to our random hash
})) || '';
}
footnoteName = footnoteName.replace(/\s/g, '');
editor.edit((edit) => {
if (shouldInsertFootnoteRef) {
edit.insert(editor.selection.start, `[^${footnoteName}]`);
}
text = editor.document.getText();
const emptyLinesAbove = text.slice(-1) === '\n' ? '\n' : '\n\n';
const endPosition = editor.document.positionAt(text.length);
edit.insert(endPosition, `${emptyLinesAbove}[^${footnoteName}]: `);
const newEndPosition = editor.document.positionAt(editor.document.getText().length);
editor.selection = new vscode.Selection(newEndPosition, newEndPosition); // set cursor
editor.revealRange(new vscode.Range(newEndPosition, nextLine(newEndPosition))); // scroll to
});
});
}
exports.default = insertFootnote;
The text was updated successfully, but these errors were encountered:
This extension is brilliant!
I've edited locally insertFootnote.js with the following code to mimic the behaviour of this atom extension, which generates a random hash for each footnote and "removes the hassle of having to track footnote numbering through the file or between collaborators".
It works well. Do you think this could be a worthwhile option to add to your extension?
The text was updated successfully, but these errors were encountered: