Editor: column counter + 80-char hint in bottom bar
This commit is contained in:
@@ -19,6 +19,17 @@
|
|||||||
let dragOver = false;
|
let dragOver = false;
|
||||||
let fileInput: HTMLInputElement;
|
let fileInput: HTMLInputElement;
|
||||||
let heroFileInput: HTMLInputElement;
|
let heroFileInput: HTMLInputElement;
|
||||||
|
let textarea: HTMLTextAreaElement;
|
||||||
|
let colCount = 0;
|
||||||
|
|
||||||
|
function updateCol() {
|
||||||
|
if (!textarea) return;
|
||||||
|
const pos = textarea.selectionStart ?? 0;
|
||||||
|
const lineStart = textarea.value.lastIndexOf('\n', pos - 1) + 1;
|
||||||
|
colCount = pos - lineStart + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
$: colColor = colCount >= 80 ? '#f87171' : colCount >= 70 ? '#f59e0b' : 'var(--text-5)';
|
||||||
|
|
||||||
$: section = SECTIONS.find(s => s.slug === selectedSection) ?? null;
|
$: section = SECTIONS.find(s => s.slug === selectedSection) ?? null;
|
||||||
$: subs = section?.sub ?? [];
|
$: subs = section?.sub ?? [];
|
||||||
@@ -299,11 +310,15 @@
|
|||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<textarea
|
<textarea
|
||||||
|
bind:this={textarea}
|
||||||
bind:value={content}
|
bind:value={content}
|
||||||
class="flex-1 w-full p-4 bg-transparent font-mono text-sm resize-none outline-none"
|
class="flex-1 w-full p-4 bg-transparent font-mono text-sm resize-none outline-none"
|
||||||
style="color: var(--text-2)"
|
style="color: var(--text-2)"
|
||||||
placeholder="Scrivi in markdown…"
|
placeholder="Scrivi in markdown…"
|
||||||
spellcheck="false"
|
spellcheck="false"
|
||||||
|
on:keyup={updateCol}
|
||||||
|
on:click={updateCol}
|
||||||
|
on:input={updateCol}
|
||||||
on:dragover|preventDefault={() => dragOver = true}
|
on:dragover|preventDefault={() => dragOver = true}
|
||||||
on:dragleave={() => dragOver = false}
|
on:dragleave={() => dragOver = false}
|
||||||
on:drop|preventDefault={e => { dragOver = false; if (e.dataTransfer?.files) uploadFiles(e.dataTransfer.files); }}
|
on:drop|preventDefault={e => { dragOver = false; if (e.dataTransfer?.files) uploadFiles(e.dataTransfer.files); }}
|
||||||
@@ -323,6 +338,8 @@
|
|||||||
<span class="text-zinc-600">oppure trascina un file nell'editor</span>
|
<span class="text-zinc-600">oppure trascina un file nell'editor</span>
|
||||||
<input bind:this={fileInput} type="file" accept="image/*" multiple class="hidden"
|
<input bind:this={fileInput} type="file" accept="image/*" multiple class="hidden"
|
||||||
on:change={e => e.currentTarget.files && uploadFiles(e.currentTarget.files)} />
|
on:change={e => e.currentTarget.files && uploadFiles(e.currentTarget.files)} />
|
||||||
|
<span class="ml-auto" style="color: var(--text-5)">~80 caratteri per riga per leggibilità</span>
|
||||||
|
<span style="color: {colColor}; font-variant-numeric: tabular-nums; min-width: 3.5rem; text-align: right">Col {colCount}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
Reference in New Issue
Block a user