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 config for smart quotes (close #1114) #1121

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions type/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,9 @@ export type ActionButton = {
export type EmojiConfig = {
aliases: string[][];
};

export type SmartQuotesConfig = {
enabled?: boolean;
double?: { left?: string; right?: string };
single?: { left?: string; right?: string };
};
9 changes: 8 additions & 1 deletion type/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import type { ActionButton, EmojiConfig, Shortcut } from "./client.ts";
import type {
ActionButton,
EmojiConfig,
Shortcut,
SmartQuotesConfig,
} from "./client.ts";

export interface ConfigContainer {
config: Config;
Expand Down Expand Up @@ -30,6 +35,7 @@ export type LibraryDef = {
export type Config = {
indexPage: string;
shortcuts?: Shortcut[];
// DEPRECATED: Use smartQuotes instead
useSmartQuotes?: boolean;
maximumAttachmentSize?: number;
libraries?: LibraryDef[];
Expand All @@ -44,6 +50,7 @@ export type Config = {
spaceIgnore?: string;
emoji?: EmojiConfig;
autoCloseBrackets: string;
smartQuotes?: SmartQuotesConfig;

schema: SchemaConfig;

Expand Down
30 changes: 27 additions & 3 deletions web/cm_plugins/smart_quotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,36 @@ function keyBindingForQuote(
}

export function createSmartQuoteKeyBindings(client: Client): KeyBinding[] {
if (client.config?.useSmartQuotes === false) {
// Also check the deprecated useSmartQuotes, default is true so either can disable
if (
client.config?.useSmartQuotes === false ||
client.config?.smartQuotes?.enabled === false
) {
return [];
}

let doubleLeft = "“";
let doubleRight = "”";
let singleLeft = "‘";
let singleRight = "’";
const config = client.config?.smartQuotes;
if (config) {
if (typeof config.double?.left === "string") {
doubleLeft = config.double!.left;
}
if (typeof config.double?.right === "string") {
doubleRight = config.double!.right;
}
if (typeof config.single?.left === "string") {
singleLeft = config.single!.left;
}
if (typeof config.single?.right === "string") {
singleRight = config.single!.right;
}
}

return [
keyBindingForQuote('"', "“", "”"),
keyBindingForQuote("'", "‘", "’"),
keyBindingForQuote('"', doubleLeft, doubleRight),
keyBindingForQuote("'", singleLeft, singleRight),
];
}
11 changes: 9 additions & 2 deletions website/SETTINGS.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,17 @@ shortcuts:
- command: "{[Upload: File]}"
priority: 1

# Toggles between “smart” ‘quotes’ (left and right) and "simple" 'quotes' (good ol' ASCII)
useSmartQuotes: true
# Choose which characters to auto-close
autoCloseBrackets: "([{`"
# Options for “smart” ‘quotes’ (left and right) used outside of code fragments, these are the defaults:
smartQuotes:
enabled: true # Set to false for "simple" 'quotes' (good ol' ASCII)
double:
left: '“'
right: '”'
single:
left: "‘"
right: "’"

# Defines files to ignore in a format compatible with .gitignore
spaceIgnore: |
Expand Down
Loading