lös ut förkortningar vid ny rad, stor bokstav efter stort skiljetecken

This commit is contained in:
botvid johansson 2025-02-13 14:10:14 +01:00
parent 31dec07683
commit 6fdbc88910
3 changed files with 47 additions and 34 deletions

View File

@ -9,22 +9,22 @@
import { cacheShortforms, expandShortform } from '../modules/shortforms';
import { defaultExpanders } from '../modules/keyboard';
import { db, type Shortform } from '../db/main';
import { liveQuery } from "dexie";
import { liveQuery } from 'dexie';
import * as Select from "$lib/components/ui/select/index.js";
import * as Select from '$lib/components/ui/select/index.js';
let styles = $derived({
"text-bg": "#333333",
"text-fg": "#baff00",
"text-font": textSettings.font,
"text-size": textSettings.size + "px"
})
'text-bg': '#333333',
'text-fg': '#baff00',
'text-font': textSettings.font,
'text-size': textSettings.size + 'px'
});
let selectedStandardList = {}
let selectedStandardList = {};
const selectedStandardListChanged = (v) => {
shortforms.standardList = v.value
shortforms.standardList = v.value;
shortforms.cache = cacheShortforms([Number(v.value)]);
}
};
let state = {
capitalizeNext: true,
currentWord: ''
@ -33,7 +33,7 @@
let textarea: HTMLTextAreaElement;
onMount(() => {
initShortformState()
initShortformState();
shortforms.cache = cacheShortforms([890324]);
if (browser) {
let t = document.getElementById('doc') as HTMLTextAreaElement;
@ -44,20 +44,24 @@
}, 25);
}
}
});
const standardLists = $derived(liveQuery( async () => {
return await db.lists.toArray()
}))
const standardLists = $derived(
liveQuery(async () => {
return await db.lists.toArray();
})
);
let css = Object.entries(styles)
.map(([key, value]) => `--${key}:${value}`)
.join(';')
const cssVarStyles = $derived({css})
.map(([key, value]) => `--${key}:${value}`)
.join(';');
const cssVarStyles = $derived({ css });
const expand = (e: InputEvent) => {
const expander = e.data as string;
let expander = e.data as string;
// console.log("expander:", expander);
if (e.inputType == 'insertLineBreak') {
expander = '\n';
}
if (defaultExpanders.has(expander)) {
const expanderRules = defaultExpanders.get(expander)!;
const currentWord = getCurrentWord(textarea).trim();
@ -67,7 +71,9 @@
state.capitalizeNext = true;
}
if (expandedPhrase != '') {
insertExpandedPhrase(textarea, expander, currentWord.length, expandedPhrase);
const pos = insertExpandedPhrase(textarea, expander, currentWord.length, expandedPhrase);
textarea.blur();
textarea.focus();
e.preventDefault();
}
}
@ -84,19 +90,20 @@
if (e.inputType == 'insertText') {
const key = e.data || '';
if (e.data == null) return;
if (state.capitalizeNext) {
if (key != ' ' && state.capitalizeNext) {
insertText(textarea, key.toUpperCase());
state.capitalizeNext = false;
e.preventDefault();
}
expand(e);
}
if (e.inputType == 'insertText') {
if (e.inputType == 'insertLineBreak') {
expand(e);
}
};
</script>
<div class="docContainer h-full flex flex-col" role="application" id="docContainer">
<div class="docContainer flex h-full flex-col" role="application" id="docContainer">
<textarea
bind:this={ref}
style="
@ -128,7 +135,7 @@
.textarea {
color: var(--text-fg, black);
background-color: var(--text-bg, white);
font-family: var(--text-font, "Arial");
font-size: var(--text-size, "20px");
font-family: var(--text-font, 'Arial');
font-size: var(--text-size, '20px');
}
</style>

View File

@ -4,10 +4,11 @@ export const insertText = (textarea: HTMLTextAreaElement, text: string) => {
textarea.setRangeText(text, start, end, "end");
};
export const insertExpandedPhrase = (textarea: HTMLTextAreaElement, expander: string, len: number, text: string) => {
export const insertExpandedPhrase = (textarea: HTMLTextAreaElement, expander: string, len: number, text: string): number => {
const start = textarea.selectionStart - len;
const end = textarea.selectionStart;
textarea.setRangeText(text.concat(expander), start, end, "end");
return end
};
const findIndexOfCurrentWord = (textarea: HTMLTextAreaElement) => {

View File

@ -8,6 +8,11 @@ let fullscreen = true;
export const defaultExpanders: Map<string, ExpanderType> = new Map();
export const hotkeys: Map<string, any> = new Map();
defaultExpanders.set("\n", {
key: { keyCode: 13, shiftKey: false },
symbol: "\n",
fullstop: true,
});
defaultExpanders.set(" ", {
key: { keyCode: 190, shiftKey: false },
symbol: " ",
@ -139,7 +144,7 @@ hotkeys.set("F11", {
action: (e) => {
console.log("Toggle fullscreen")
console.log(PUBLIC_TAURI)
if(PUBLIC_TAURI == true) {
if (PUBLIC_TAURI == true) {
e.preventDefault()
if (fullscreen) {
getCurrentWindow().setFullscreen(false).then(() => {