Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

space-indicator first draft #360

Merged
merged 7 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11,303 changes: 9,504 additions & 1,799 deletions package-lock.json

Large diffs are not rendered by default.

15 changes: 9 additions & 6 deletions src/components/editor/Space.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
import InsertionPointView from './InsertionPointView.svelte';
import type { InsertionPoint } from '../../edit/Drag';
import { EXPLICIT_TAB_TEXT, TAB_TEXT } from '../../parser/Spaces';
import {locales, DB, spaceIndicator} from '../../db/Database';

export let token: Token;
export let space: string;
export let additional: string;
export let insertion: InsertionPoint | undefined = undefined;

$: insertionIndex =
insertion !== undefined
? space.split('\n', insertion.line).join('\n').length + 1
Expand All @@ -19,20 +20,22 @@
$: beforeSpaces =
insertionIndex === undefined
? []
: render(space.substring(0, insertionIndex), true);
: render(space.substring(0, insertionIndex), true, $spaceIndicator);
// If there's no insertion, just render the space, otherwise render the right side of the insertion.
$: afterSpaces = render(
insertionIndex === undefined ? space : space.substring(insertionIndex),
true
true,
$spaceIndicator
);

$: additionalSpaces =
additional.length === 0 ? [] : render(additional, false);
additional.length === 0 ? [] : render(additional, false, $spaceIndicator);

function render(text: string, explicit: boolean): string[] {
function render(text: string, explicit: boolean, spaceIndicator:boolean): string[] {
console.log('spaceIndicator change', spaceIndicator);
return (
explicit
? text.replaceAll(' ', '·').replaceAll('\t', EXPLICIT_TAB_TEXT)
? (spaceIndicator ? text.replaceAll(' ', '·').replaceAll('\t', EXPLICIT_TAB_TEXT):text.replaceAll('\t', EXPLICIT_TAB_TEXT))
: text.replaceAll(' ', '\xa0').replaceAll('\t', TAB_TEXT)
).split('\n');
}
Expand Down
14 changes: 14 additions & 0 deletions src/components/settings/Settings.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
mic,
Settings,
dark,
spaceIndicator,
} from '../../db/Database';
import Arrangement from '../../db/Arrangement';
import Options from '../widgets/Options.svelte';
Expand Down Expand Up @@ -208,6 +209,19 @@
modes={['☼', '☽', '☼/☽']}
/>
</p>
<p
><Mode
descriptions={$locales.get(
(l) => l.ui.dialog.settings.mode.space,
)}
choice={$spaceIndicator === false ? 1 : 0}
select={(choice) =>
Settings.setSpace(
choice === 0 ? true : false,
)}
modes={['On', 'Off']}
/>
</p>
</Dialog>
</div>

Expand Down
2 changes: 2 additions & 0 deletions src/components/widgets/Mode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
export let choice: number;
export let select: (choice: number) => void;
export let active = true;
console.log(descriptions);

</script>

<div class="mode">
Expand Down
1 change: 1 addition & 0 deletions src/db/Database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ export const locales = DB.Locales.locales;
export const writingLayout = Settings.settings.writingLayout.value;
export const camera = Settings.settings.camera.value;
export const dark = Settings.settings.dark.value;
export const spaceIndicator = Settings.settings.space.value;
export const mic = Settings.settings.mic.value;
export const blocks = Settings.settings.blocks.value;
export const localized = Settings.settings.localized.value;
Expand Down
1 change: 1 addition & 0 deletions src/db/Setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export default class Setting<Type> {

set(database: Database, value: Type) {
if (this.equal(this.get(), value)) return;
console.log('setting value changed, now the value is:', value)

// Save in the store, notifying subscribers about the change.
this.value.set(value);
Expand Down
10 changes: 10 additions & 0 deletions src/db/SettingsDatabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { DarkSetting } from './DarkSetting';
import { doc, getDoc } from 'firebase/firestore';
import { firestore } from './firebase';
import { CreatorCollection } from './CreatorDatabase';
import { SpaceSetting } from './SpaceSetting';

/** The schema of the record written to the creators collection. */
export type SettingsSchemaV1 = {
Expand Down Expand Up @@ -63,6 +64,7 @@ export default class SettingsDatabase {
blocks: BlocksSetting,
localized: LocalizedSetting,
dark: DarkSetting,
space: SpaceSetting,
};

/** A derived store based on animation factor */
Expand Down Expand Up @@ -164,10 +166,18 @@ export default class SettingsDatabase {
this.settings.dark.set(this.database, dark);
}

setSpace(space: boolean) {
this.settings.space.set(this.database, space);
}

getDark() {
return this.settings.dark.get();
}

getSpace() {
return this.settings.space.get();
}

setBlocks(on: boolean) {
this.settings.blocks.set(this.database, on);
}
Expand Down
9 changes: 9 additions & 0 deletions src/db/SpaceSetting.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Setting from './Setting';

export const SpaceSetting = new Setting<boolean>(
'space',
false,
true,
(value) => typeof value === 'boolean',
(current, value) => current === value
);
2 changes: 2 additions & 0 deletions src/locale/UITexts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,8 @@ type UITexts = {
dark: ModeText<[string, string, string]>;
/** The writing layout direction */
writing: ModeText<[string, string, string]>;
/** The space_indicator on/off mode */
space: ModeText<[string, string]>;
};
options: {
/** The label for the microphone drop down */
Expand Down
7 changes: 7 additions & 0 deletions src/locale/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -4158,6 +4158,13 @@
"use device setting"
]
},
"space": {
"label": "space indicator",
"modes": [
"open",
"closed"
]
},
"writing": {
"label": "writing layout",
"modes": [
Expand Down
2 changes: 2 additions & 0 deletions src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { locales, DB, animationFactor, dark } from '../db/Database';
import { browser } from '$app/environment';
import { getLanguageDirection } from '../locale/LanguageCode';
console.log('*****初始值dark', $dark);

/** Expose the translations as context, updating them as necessary */
$: setContext(LocalesSymbol, $locales);
Expand Down Expand Up @@ -58,6 +59,7 @@

/** When dark mode changes, update the body's dark class */
$: if (browser) {
console.log('dark mode changes', $dark)
if ($dark === true || ($dark === null && prefersDark()))
document.body.classList.add('dark');
else document.body.classList.remove('dark');
Expand Down
Loading