style(journals): apply expanded 80-width formatting and snake_case
- Batch formatted all Journals module files using Prettier with printWidth: 80. - Refactored preventDefault to prevent_default across all Svelte components. - Standardized line breaks for imports and long attribute lists for better readability. - Ensured consistent snake_case naming for internal identifiers.
This commit is contained in:
@@ -1,19 +1,28 @@
|
||||
/**
|
||||
* Wraps the current selection in CodeMirror with the given prefix and suffix.
|
||||
*/
|
||||
export function wrapSelection(view: any, prefix: string, suffix: string = prefix) {
|
||||
export function wrapSelection(
|
||||
view: any,
|
||||
prefix: string,
|
||||
suffix: string = prefix
|
||||
) {
|
||||
if (!view || view.updateInProgress) return;
|
||||
|
||||
|
||||
const { state } = view;
|
||||
view.dispatch(state.changeByRange((range: any) => {
|
||||
return {
|
||||
changes: [
|
||||
{from: range.from, insert: prefix},
|
||||
{from: range.to, insert: suffix}
|
||||
],
|
||||
range: range.constructor.range(range.from + prefix.length, range.to + prefix.length)
|
||||
};
|
||||
}));
|
||||
view.dispatch(
|
||||
state.changeByRange((range: any) => {
|
||||
return {
|
||||
changes: [
|
||||
{ from: range.from, insert: prefix },
|
||||
{ from: range.to, insert: suffix }
|
||||
],
|
||||
range: range.constructor.range(
|
||||
range.from + prefix.length,
|
||||
range.to + prefix.length
|
||||
)
|
||||
};
|
||||
})
|
||||
);
|
||||
view.focus();
|
||||
}
|
||||
|
||||
@@ -22,32 +31,49 @@ export function wrapSelection(view: any, prefix: string, suffix: string = prefix
|
||||
*/
|
||||
export function toggleLinePrefix(view: any, prefix: string) {
|
||||
if (!view || view.updateInProgress) return;
|
||||
|
||||
|
||||
const { state } = view;
|
||||
view.dispatch(state.changeByRange((range: any) => {
|
||||
const lines = [];
|
||||
for (let pos = range.from; pos <= range.to; ) {
|
||||
const line = state.doc.lineAt(pos);
|
||||
lines.push(line);
|
||||
pos = line.to + 1;
|
||||
}
|
||||
|
||||
const isAlreadyPrefixed = lines.every(l => l.text.startsWith(prefix));
|
||||
const lineChanges = lines.map(l => {
|
||||
if (isAlreadyPrefixed) {
|
||||
return { from: l.from, to: l.from + prefix.length, insert: '' };
|
||||
} else {
|
||||
return { from: l.from, insert: prefix };
|
||||
view.dispatch(
|
||||
state.changeByRange((range: any) => {
|
||||
const lines = [];
|
||||
for (let pos = range.from; pos <= range.to; ) {
|
||||
const line = state.doc.lineAt(pos);
|
||||
lines.push(line);
|
||||
pos = line.to + 1;
|
||||
}
|
||||
});
|
||||
|
||||
const newFrom = range.from + (isAlreadyPrefixed ? -prefix.length : prefix.length);
|
||||
const newTo = range.to + (isAlreadyPrefixed ? (-prefix.length * lines.length) : (prefix.length * lines.length));
|
||||
const isAlreadyPrefixed = lines.every((l) =>
|
||||
l.text.startsWith(prefix)
|
||||
);
|
||||
const lineChanges = lines.map((l) => {
|
||||
if (isAlreadyPrefixed) {
|
||||
return {
|
||||
from: l.from,
|
||||
to: l.from + prefix.length,
|
||||
insert: ''
|
||||
};
|
||||
} else {
|
||||
return { from: l.from, insert: prefix };
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
changes: lineChanges,
|
||||
range: range.constructor.range(newFrom, Math.max(newFrom, newTo))
|
||||
};
|
||||
}));
|
||||
const newFrom =
|
||||
range.from +
|
||||
(isAlreadyPrefixed ? -prefix.length : prefix.length);
|
||||
const newTo =
|
||||
range.to +
|
||||
(isAlreadyPrefixed
|
||||
? -prefix.length * lines.length
|
||||
: prefix.length * lines.length);
|
||||
|
||||
return {
|
||||
changes: lineChanges,
|
||||
range: range.constructor.range(
|
||||
newFrom,
|
||||
Math.max(newFrom, newTo)
|
||||
)
|
||||
};
|
||||
})
|
||||
);
|
||||
view.focus();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user