mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-16 20:45:33 -08:00
Warn about a too-long tab name as you type
AI Assisted
This commit is contained in:
1 parent
9f4ee75c0b
commit
4ca53ccf3a
5 files changed
+43
-2
No files matched your search
@@ -3786,7 +3786,8 @@
|
||||
<dialog class="modal notepad-sub" id="notepad-name-dlg" aria-labelledby="notepad-name-label">
|
||||
<form class="notepad-name-form" id="notepad-name-form" novalidate>
|
||||
<h2 id="notepad-name-label">Name this tab</h2>
|
||||
<input type="text" id="notepad-name" autocomplete="off" spellcheck="false" aria-describedby="notepad-name-error" />
|
||||
<input type="text" id="notepad-name" autocomplete="off" spellcheck="false" aria-describedby="notepad-name-error notepad-name-count" />
|
||||
<p class="help notepad-name-count" id="notepad-name-count"></p>
|
||||
<p class="help notepad-name-error" id="notepad-name-error" aria-live="polite"></p>
|
||||
<div class="modal-actions">
|
||||
<button type="button" class="btn ghost" id="notepad-name-cancel">Cancel</button>
|
||||
@@ -4102,6 +4103,7 @@
|
||||
<div class="footer-actions">
|
||||
<span class="hint" id="send-hint"></span>
|
||||
<button type="button" class="btn ghost" id="btn-clear" hidden>Clear</button>
|
||||
<button type="button" class="btn" id="btn-dashboard" hidden>Back to the dashboard</button>
|
||||
<button type="button" class="btn primary" id="btn-send" disabled>Send to Plan2Code</button>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
NOT_LOADED,
|
||||
SAVE_START,
|
||||
TAB_ID_RE,
|
||||
TAB_NAME_MAX,
|
||||
cleanTabName,
|
||||
errorSentence,
|
||||
keepsText,
|
||||
@@ -274,7 +275,7 @@ function drawTabs() {
|
||||
drawSent();
|
||||
$("notepad-tab-new").disabled = busy;
|
||||
$("notepad-empty-new").disabled = busy;
|
||||
$("notepad-name-save").disabled = busy;
|
||||
$("notepad-name-save").disabled = busy || nameTooLong();
|
||||
}
|
||||
|
||||
// Put a read tab on screen: its text, its pictures, the bar. `keep` leaves
|
||||
@@ -390,6 +391,24 @@ function nameError(sentence) {
|
||||
$("notepad-name").focus();
|
||||
}
|
||||
|
||||
// The name as the server would count it: trimmed, inner spaces collapsed.
|
||||
const nameLength = () => [...$("notepad-name").value.trim().replace(/\s+/g, " ")].length;
|
||||
const nameTooLong = () => nameLength() > TAB_NAME_MAX;
|
||||
|
||||
// The count under the box, and the too-long warning and Save as you type,
|
||||
// not only once Save is pressed. Other problems are still said on Save.
|
||||
let liveWarning = false;
|
||||
function paintNameCount() {
|
||||
const over = nameTooLong();
|
||||
const count = $("notepad-name-count");
|
||||
count.textContent = `${nameLength()}/${TAB_NAME_MAX}`;
|
||||
count.classList.toggle("over", over);
|
||||
if (over) $("notepad-name-error").textContent = tabNameProblem([], $("notepad-name").value);
|
||||
else if (liveWarning) $("notepad-name-error").textContent = "";
|
||||
liveWarning = over;
|
||||
$("notepad-name-save").disabled = busy || over;
|
||||
}
|
||||
|
||||
function openNameForm(mode) {
|
||||
if (busy || (mode === "rename" && !activeId)) return;
|
||||
closeDelete();
|
||||
@@ -399,6 +418,7 @@ function openNameForm(mode) {
|
||||
if (!$("notepad-name-dlg").open) $("notepad-name-dlg").showModal();
|
||||
const input = $("notepad-name");
|
||||
input.value = mode === "rename" ? nameOf(activeId) : "";
|
||||
paintNameCount();
|
||||
input.focus();
|
||||
input.select();
|
||||
}
|
||||
@@ -911,6 +931,7 @@ export function wireNotepad() {
|
||||
$("notepad-delete-keep").addEventListener("click", () => closeDelete(true));
|
||||
$("notepad-delete-go").addEventListener("click", confirmDelete);
|
||||
$("notepad-name-cancel").addEventListener("click", () => closeNameForm());
|
||||
$("notepad-name").addEventListener("input", paintNameCount);
|
||||
$("notepad-name-form").addEventListener("submit", (e) => {
|
||||
e.preventDefault();
|
||||
submitName();
|
||||
|
||||
@@ -199,6 +199,8 @@
|
||||
font: inherit;
|
||||
}
|
||||
.notepad-name-form input:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; }
|
||||
.notepad-name-count { margin: 4px 0 0; text-align: right; font-variant-numeric: tabular-nums; }
|
||||
.notepad-name-count.over { color: var(--warn); }
|
||||
.notepad-name-error { min-height: 1.2em; margin: 6px 0 0; }
|
||||
.notepad-name-error:not(:empty) { color: var(--warn); }
|
||||
.modal.notepad-delete { border-color: var(--warn); }
|
||||
|
||||
Reference in new issue
Block a user