Skip to content

Commit

Permalink
improves saved snippets deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianoc committed Apr 11, 2024
1 parent c54c00d commit d75ff46
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
19 changes: 10 additions & 9 deletions Cecilifier.Web/wwwroot/css/snippethandler.css
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
/* unvisited link */
a.shortcut:link {
color: #7c95ec;
div.shortcut a:link {
color: #d7f678;
}

/* visited link */
a.shortcut:visited {
div.shortcut a:visited {
color: #91f191;
}

/* mouse over link */
a.shortcut:hover {
div.shortcut a:hover {
color: #f6e490;
}

/* selected link */
a.shortcut:active {
div.shortcut a:active {
color: #7474ea;
}
}

div.shortcut:hover {
background-color: rgba(127, 14, 142, 0.5);
}
7 changes: 5 additions & 2 deletions Cecilifier.Web/wwwroot/js/cecilifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ using System;
class Foo
{
void Bar() => Console.WriteLine("Hello World!");
};`);
}`);

csharpCode.focus();
focusedEditor = csharpCode;
Expand Down Expand Up @@ -248,12 +248,15 @@ function configureKeyboardShortcuts() {
});

csharpCode.addCommand(monaco.KeyMod.CtrlCmd + monaco.KeyMod.Alt + monaco.KeyCode.KeyL, function() {
showListOfLocalyStoredSnippets();
showListOfLocallyStoredSnippets();
});

// Cecilified code
cecilifiedCode.addCommand(monaco.KeyMod.CtrlCmd + monaco.KeyCode.BracketLeft , decreaseFocusedEditorFontSize);
cecilifiedCode.addCommand(monaco.KeyMod.CtrlCmd + monaco.KeyCode.BracketRight , increaseFocusedEditorFontSize);
cecilifiedCode.addCommand(monaco.KeyMod.CtrlCmd + monaco.KeyMod.Alt + monaco.KeyCode.KeyL, function() {
showListOfLocallyStoredSnippets();
});
}

function configureCursorInformationVisibility(show) {
Expand Down
16 changes: 12 additions & 4 deletions Cecilifier.Web/wwwroot/js/cecilifier.snippethandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,29 @@ function cecilifyFromSnippet(counter) {
}
}

function showListOfLocalyStoredSnippets() {
function showListOfLocallyStoredSnippets() {
let snippetNames = [];
for(let i = 0; i < window.localStorage.length; i++) {
let key = window.localStorage.key(i);
if (key.startsWith(saved_snippet_prefix)) {
let snippetName= key.substring(saved_snippet_prefix.length);
snippetNames.push(`<a href="${snippetName}" class="shortcut">${snippetName}</a>`);
snippetNames.push(`<div id="${snippetName}-to-remove" class="shortcut"><a href="#" title="Removes ${snippetName}." onclick="removeSnippet('${snippetName}');"><i class="fa-solid fa-trash-can"></i></a> <a href="${snippetName}" title="Loads ${snippetName}.">${snippetName}</a><br /></div>`);
}
}

SnackBar({
message: `<b>List of saved snippets</b><br /><br/>${snippetNames.reduce( (acc, current) => `${acc}<br />${current}`)}`,
message: `<b>Saved snippets</b><br /><br/>${snippetNames.reduce( (acc, current) => `${acc}${current}`)}`,
dismissible: true,
status: "Info",
timeout: false,
icon: "Info"
icon: "!"
});
}

function removeSnippet(snippetName) {
if (confirm(`Are you sure you want to remove the snippet '${snippetName}' ?`)) {
window.localStorage.removeItem(saved_snippet_prefix + snippetName);
let toBeRemoved = document.getElementById(`${snippetName}-to-remove`);
toBeRemoved.parentNode.removeChild(toBeRemoved);
}
}

0 comments on commit d75ff46

Please sign in to comment.