Skip to content

Commit 335eda8

Browse files
committed
feat(feature): cSS: spare blocks
1 parent 036a31a commit 335eda8

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

src/app.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919

2020
splitByLines, splitBySentences, splitByWords, removeNewLines,
2121
} from './commands'
22-
import { improveCursorMovement_KeyDownListener, improveSearch_KeyDownListener } from './features'
22+
import { improveCursorMovement_KeyDownListener, improveSearch_KeyDownListener, spareBlocksFeature } from './features'
2323
import { getChosenBlocks, p, scrollToBlock } from './utils'
2424

2525

@@ -76,6 +76,15 @@ const settingsSchema: SettingSchemaDesc[] = [
7676
enumChoices: ['Yes', 'No'],
7777
default: 'Yes',
7878
},
79+
{
80+
key: 'enableSpareBlocks',
81+
title: 'Enable spare space between 1-level blocks?',
82+
description: ``.trim(),
83+
type: 'enum',
84+
enumPicker: 'radio',
85+
enumChoices: ['Yes', 'No'],
86+
default: 'Yes',
87+
},
7988
{
8089
key: 'headingViews',
8190
type: 'heading',
@@ -115,6 +124,9 @@ async function onAppSettingsChanged(current, old) {
115124
if (current.enableSearchImprovements === 'Yes')
116125
parent.document.addEventListener('keydown', improveSearch_KeyDownListener, true)
117126
}
127+
128+
if (!old || current.enableSpareBlocks !== old.enableSpareBlocks)
129+
spareBlocksFeature(current.enableSpareBlocks === 'Yes')
118130
}
119131

120132

src/css/spare_blocks.css

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* make a spare space between 1-level blocks */
2+
.page:has(> div > div > div > .page-title) div.ls-block[level="1"]:not(:first-child),
3+
.page:has(> div > div > div > div > .journal-title) div.ls-block[level="1"]:not(:first-child) {
4+
margin-top: 20px;
5+
}
6+
.whiteboard div.ls-block[level="1"]:not(:first-child) {
7+
margin-top: 0px !important;
8+
}
9+
[data-refs-self*=".tabular"] > .block-children-container > .block-children > div.ls-block[level="1"]:not(:first-child) {
10+
margin-top: 0px !important;
11+
}
12+
.embed-page div.ls-block[level="1"]:not(:first-child) {
13+
margin-top: 0px !important;
14+
}
15+
.embed-block div.ls-block[level="1"]:not(:first-child) {
16+
margin-top: 0px !important;
17+
}
18+
#right-sidebar-container div.ls-block[level="1"]:not(:first-child) {
19+
margin-top: 0px !important;
20+
}
21+
.references-blocks div.ls-block[level="1"]:not(:first-child) {
22+
margin-top: 0px !important;
23+
}
24+
.references.page-unlinked div.ls-block[level="1"]:not(:first-child) {
25+
margin-top: 0px !important;
26+
}

src/features.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { setNativeValue } from './utils'
1+
import { provideStyle, setNativeValue } from './utils'
2+
3+
import spareBlocksStyle from './css/spare_blocks.css?inline'
24

35

46
/**
@@ -94,3 +96,15 @@ export async function improveSearch_KeyDownListener(e: KeyboardEvent) {
9496
if (target.value.toLowerCase() !== text.toLowerCase())
9597
setNativeValue(target, text, true)
9698
}
99+
100+
101+
/**
102+
* CSS: Make spare space between 1-level blocks
103+
*/
104+
export async function spareBlocksFeature(toggle: boolean) {
105+
const key = 'spare-blocks'
106+
if (toggle)
107+
provideStyle(key, spareBlocksStyle)
108+
else
109+
provideStyle(key)
110+
}

0 commit comments

Comments
 (0)