Custom task statuses plus various fixes

This commit is contained in:
Zef Hemel
2023-09-01 16:57:29 +02:00
parent 9b5fa44fb6
commit 2ee20af5c8
24 changed files with 374 additions and 118 deletions
+3
View File
@@ -96,6 +96,9 @@ export class Client {
parent: Element,
public syncMode = false,
) {
if (!syncMode) {
this.fullSyncCompleted = true;
}
// Generate a semi-unique prefix for the database so not to reuse databases for different space paths
this.dbPrefix = "" + simpleHash(window.silverBulletConfig.spaceFolderPath);
+14 -5
View File
@@ -37,12 +37,13 @@ export function taskListPlugin(
syntaxTree(state).iterate({
enter({ type, from, to, node }) {
if (type.name !== "Task") return;
let checked = false;
// true/false if this is a checkbox, undefined when it's a custom-status task
let checkboxStatus: boolean | undefined;
// Iterate inside the task node to find the checkbox
node.toTree().iterate({
enter: (ref) => iterateInner(ref.type, ref.from, ref.to),
});
if (checked) {
if (checkboxStatus === true) {
widgets.push(
Decoration.mark({
tagName: "span",
@@ -52,14 +53,22 @@ export function taskListPlugin(
}
function iterateInner(type: NodeType, nfrom: number, nto: number) {
if (type.name !== "TaskMarker") return;
if (type.name !== "TaskState") return;
if (isCursorInRange(state, [from + nfrom, from + nto])) return;
const checkbox = state.sliceDoc(from + nfrom, from + nto);
// Checkbox is checked if it has a 'x' in between the []
if ("xX".includes(checkbox[1])) checked = true;
if (checkbox === "[x]" || checkbox === "[X]") {
checkboxStatus = true;
} else if (checkbox === "[ ]") {
checkboxStatus = false;
}
if (checkboxStatus === undefined) {
// Not replacing it with a widget
return;
}
const dec = Decoration.replace({
widget: new CheckboxWidget(
checked,
checkboxStatus,
from + nfrom + 1,
onCheckboxClick,
),
+1
View File
@@ -22,6 +22,7 @@ export default function highlightStyles(mdExtension: MDExt[]) {
{ tag: ct.AttributeNameTag, class: "sb-atom" },
{ tag: ct.TaskTag, class: "sb-task" },
{ tag: ct.TaskMarkerTag, class: "sb-task-marker" },
{ tag: ct.TaskStateTag, class: "sb-task-state" },
{ tag: ct.CodeInfoTag, class: "sb-code-info" },
{ tag: ct.CommentTag, class: "sb-comment" },
{ tag: ct.CommentMarkerTag, class: "sb-comment-marker" },
+4
View File
@@ -381,6 +381,10 @@
color: var(--editor-task-marker-color);
}
.sb-task-state {
color: var(--editor-task-state-color);
}
.sb-line-comment {
background-color: var(--editor-code-comment-color); // rgba(255, 255, 0, 0.5);
}
+4
View File
@@ -312,6 +312,10 @@
font-size: 91%;
}
.sb-task-state {
font-size: 91%;
}
.sb-directive-start {
border-top-left-radius: 10px;
border-top-right-radius: 10px;
+2
View File
@@ -105,6 +105,8 @@ html {
--editor-directive-color: #5b5b5b;
--editor-directive-info-color: var(--subtle-color);
--editor-task-marker-color: var(--subtle-color);
--editor-task-state-color: var(--subtle-color);
--ui-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
"Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji",