Skip to content
Open
Show file tree
Hide file tree
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
Binary file added .DS_Store
Binary file not shown.
8 changes: 8 additions & 0 deletions css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,14 @@ canvas {
display: block;
}

.fontsize-btn {
padding: 0 6px;
margin: 0 2px;
font-size: 12px;
line-height: 1.2;
cursor: pointer;
}

.filelist ul {
padding: 0;
margin: 0;
Expand Down
13 changes: 13 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@
<li id="settingsmenu">Settings...</li>
</ul>
</li>
<li>
View
<ul>
<li>
<label>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why a <label>?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably just copy-pasted from the others. When a <label> wraps text and a single <input>, like in #143, then it allows clicking the text to affect the input. But here there are two buttons, so the "Font size:" label shouldn't actually be a <label> for either of them.

Font size:
<button id="view_font_decrease" class="fontsize-btn" title="Decrease (Ctrl+-)">−</button>
<span id="view_font_size_display">14</span>px
<button id="view_font_increase" class="fontsize-btn" title="Increase (Ctrl+=)">+</button>
</label>
</li>
</ul>
</li>
<li>
About
<ul>
Expand Down
64 changes: 64 additions & 0 deletions js/text-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,70 @@ export function register(div_id, compileCode) {
event.stop();
});

// Font size control via keyboard shortcuts (Ctrl+=/-, Ctrl+0) and View menu buttons
// The variable of font size is saved in the local storage with limit 8 to 32.
// It is implemented through ACE editor functions
(function () {
var DEFAULT_SIZE = 14;
var MIN_SIZE = 8;
var MAX_SIZE = 32;
var STORAGE_KEY = 'aceFontSize';

var currentSize = parseInt(localStorage.getItem(STORAGE_KEY)) || DEFAULT_SIZE;
e.setFontSize(currentSize + 'px');

function applyFontSize(size) {
e.setFontSize(size + 'px');
var display = document.getElementById('view_font_size_display');
if (display) display.textContent = size;
}

window.changeEditorFontSize = function (delta) {
var newSize = currentSize + delta;
if (newSize < MIN_SIZE || newSize > MAX_SIZE) return;
currentSize = newSize;
applyFontSize(currentSize);
localStorage.setItem(STORAGE_KEY, currentSize);
};

// Initialize display
applyFontSize(currentSize);

e.commands.addCommand({
name: 'increaseFontSize',
bindKey: { win: 'Ctrl-=', mac: 'Command-=' },
exec: function () {
window.changeEditorFontSize(1);
},
});

e.commands.addCommand({
name: 'decreaseFontSize',
bindKey: { win: 'Ctrl--', mac: 'Command--' },
exec: function () {
window.changeEditorFontSize(-1);
},
});

e.commands.addCommand({
name: 'resetFontSize',
bindKey: { win: 'Ctrl-0', mac: 'Command-0' },
exec: function () {
currentSize = DEFAULT_SIZE;
applyFontSize(currentSize);
localStorage.setItem(STORAGE_KEY, currentSize);
},
});
})();

// Bind View menu buttons
(function () {
var decrBtn = document.getElementById('view_font_decrease');
var incrBtn = document.getElementById('view_font_increase');
if (decrBtn) decrBtn.addEventListener('click', function () { window.changeEditorFontSize(-1); });
if (incrBtn) incrBtn.addEventListener('click', function () { window.changeEditorFontSize(1); });
})();

editors.push(e);
}

Expand Down
Binary file added starting_project/.DS_Store
Binary file not shown.
Loading