Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 121 additions & 10 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,56 @@
</div>
<div id="supercode-editor"></div>
<div id="supercode-footer">
<button id="supercode-cancel-btn">
Cancel
</button>
<button id="supercode-save-btn">
Save
</button>
<div id="supercode-theme-container">
<label for="supercode-theme-dropdown">Select Theme:</label>
<select id="supercode-theme-dropdown">
<optgroup label="LIGHT">
<option value="chrome">Chrome</option>
<option value="clouds">Clouds</option>
<option value="crimson_editor">Crimson Editor</option>
<option value="dawn">Dawn</option>
<option value="dreamweaver">Dreamweaver</option>
<option value="eclipse">Eclipse</option>
<option value="github">GitHub</option>
<option value="iplastic">IPlastic</option>
<option value="katzenmilch">KatzenMilch</option>
<option value="kuroir">Kuroir</option>
<option value="solarized_light">Solarized Light</option>
<option value="sqlserver">SQL Server</option>
<option value="textmate">TextMate</option>
<option value="tomorrow">Tomorrow</option>
<option value="xcode">XCode</option>
</optgroup>
<optgroup label="DARK">
<option value="ambiance">Ambiance</option>
<option value="chaos">Chaos</option>
<option value="clouds_midnight">Clouds Midnight</option>
<option value="cobalt">Cobalt</option>
<option value="dracula">Dracula</option>
<option value="gob">Green on Black</option>
<option value="gruvbox">Gruvbox</option>
<option value="idle_fingers">idle Fingers</option>
<option value="kr_theme">krTheme</option>
<option value="merbivore">Merbivore</option>
<option value="merbivore_soft">Merbivore Soft</option>
<option value="mono_industrial">Mono Industrial</option>
<option value="monokai">Monokai</option>
<option value="pastel_on_dark">Pastel on Dark</option>
<option value="solarized_dark">Solarized Dark</option>
<option value="terminal">Terminal</option>
<option value="tomorrow_night">Tomorrow Night</option>
<option value="tomorrow_night_blue">Tomorrow Night Blue</option>
<option value="tomorrow_night_bright">Tomorrow Night Bright</option>
<option value="tomorrow_night_eighties">Tomorrow Night 80s</option>
<option value="twilight">Twilight</option>
<option value="vibrant_ink">Vibrant Ink</option>
</optgroup>
</select>
</div>
<div id="supercode-button-container">
<button id="supercode-cancel-btn">Cancel</button>
<button id="supercode-save-btn">Save</button>
</div>
</div>
</div>
`
Expand Down Expand Up @@ -123,11 +167,32 @@
#supercode-footer {
padding: 0.5rem 1rem;
display: flex;
justify-content: end;
flex-direction: column;
justify-content: space-between;
align-items: center;
gap: 1rem;
border-top: 1px solid var(--supercode-modal-border);
}
#supercode-footer button {
#supercode-theme-container {
display: flex;
align-items: center;
}
#supercode-theme-container label {
margin-right: 1.0rem; /* Adjust as needed */
color: var(--supercode-modal-secondary);
padding:5px 0px 0px 0px;
}
#supercode-theme-container select {
/* Add styles for select dropdown */
padding:6px 3px;
min-width:200px !important;
border-radius: 4px;
}
#supercode-button-container {
display: flex;
gap: 1rem;
}
#supercode-footer #supercode-button-container button {
padding: 0.5rem 1rem;
border-radius: 5px;
font-weight: bold;
Expand All @@ -136,7 +201,7 @@
min-width: 5rem;
transition: opacity 0.1s linear;
}
#supercode-footer button:hover {
#supercode-footer #supercode-button-container button:hover {
opacity: 0.8;
}
#supercode-cancel-btn {
Expand All @@ -147,6 +212,21 @@
background: var(--supercode-modal-secondary);
color: var(--supercode-modal-primary);
}
/* Media query for responsiveness */
@media (min-width: 768px) {
#supercode-footer {
flex-direction: row; /* Switch to horizontal layout */
align-items: center;
}
#supercode-theme-container {
width: auto; /* Allow select container to adjust width */
margin-bottom: 0; /* Remove margin for desktop view */
}
#supercode-button-container {
display: flex; /* Show button container */
gap: 1rem; /* Add spacing between buttons */
}
}
`;

const CLOSE_ICON_FALLBACK = `<svg width="24" height="24"><path d="M17.3 8.2 13.4 12l3.9 3.8a1 1 0 0 1-1.5 1.5L12 13.4l-3.8 3.9a1 1 0 0 1-1.5-1.5l3.9-3.8-3.9-3.8a1 1 0 0 1 1.5-1.5l3.8 3.9 3.8-3.9a1 1 0 0 1 1.5 1.5Z" fill-rule="evenodd"></path></svg>`
Expand Down Expand Up @@ -300,7 +380,30 @@
}

aceEditor.setOptions(options);
aceEditor.setTheme(`ace/theme/${Config.theme}`);

// Check if the theme cookie exists
const themeCookieExists = document.cookie.split(';').some((item) => item.trim().startsWith('supercodeTheme='));

let selectedTheme = `${Config.theme}`;

// If the cookie exists, load the theme from the cookie
if (themeCookieExists) {
selectedTheme = document.cookie
.split('; ')
.find(row => row.startsWith('supercodeTheme='))
.split('=')[1];
aceEditor.setTheme(`ace/theme/${selectedTheme}`);
} else {
aceEditor.setTheme(`ace/theme/${Config.theme}`);
}

const themeSelect = document.getElementById("supercode-theme-dropdown");
Array.from(themeSelect.options).forEach(option => {
if (option.value === selectedTheme) {
option.selected = true;
}
});

aceEditor.setFontSize(Config.fontSize);
aceEditor.setShowPrintMargin(false);
}
Expand Down Expand Up @@ -419,6 +522,8 @@
modal.element.querySelector('#supercode-editor').addEventListener('keydown', modalKeydownListener);
}

modal.element.querySelector('#supercode-theme-dropdown').addEventListener('change', onThemeHandler);

/* Update Modal based on editor's theme */
document.querySelector('body').classList.add('disable-scroll');

Expand Down Expand Up @@ -471,6 +576,12 @@
}
};

const onThemeHandler = (e) => {
const selectedTheme = e.target.value;
aceEditor.setTheme(`ace/theme/${selectedTheme}`);
document.cookie = `supercodeTheme=${selectedTheme}; expires=Fri, 31 Dec 9999 23:59:59 GMT`;
};

const getSourceCode = (value) => {
if(Config.parser){
return Config.parser(value);
Expand Down