feat: add source line number toggle by masalha-alaa · Pull Request #5111 · marktext/marktext · GitHub
Skip to content
Merged
5 changes: 5 additions & 0 deletions packages/desktop/src/main/preferences/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const commitTimer = ref<ReturnType<typeof setTimeout> | null>(null)
const viewDestroyed = ref(false)
const tabId = ref<string | null>(null)

const { theme, sourceCode } = storeToRefs(preferencesStore)
const { theme, sourceCode, sourceCodeLineNumbers } = storeToRefs(preferencesStore)
const { currentFile: currentTab } = storeToRefs(editorStore)

const isValidMuyaIndexCursor = (cursor: unknown): cursor is MuyaIndexCursorLike => {
Expand All @@ -60,6 +60,10 @@ watch(
}
)

watch(sourceCodeLineNumbers, (value) => {
editor.value?.setOption('lineNumbers', value)
})

const getMarkdownAndCursor = (cm: CMInstance) => {
let focus = cm.getCursor('head')
let anchor = cm.getCursor('anchor')
Expand Down Expand Up @@ -335,19 +339,12 @@ onMounted(() => {
const container = sourceCodeContainer.value
const codeMirrorConfig: Record<string, unknown> = {
value: markdown,
lineNumbers: true,
lineNumbers: sourceCodeLineNumbers.value,
autofocus: true,
lineWrapping: true,
styleActiveLine: true,
direction: textDirection,
viewportMargin: Infinity,
lineNumberFormatter (line: number) {
if (line % 10 === 0 || line === 1) {
return line
} else {
return ''
}
}
viewportMargin: Infinity
}

if (railscastsThemes.includes(theme.value)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@
:bool="autoCheck"
:on-change="(value) => onSelectChange('autoCheck', value)"
/>
<bool
:description="t('preferences.editor.misc.sourceCodeLineNumbers')"
:bool="sourceCodeLineNumbers"
:on-change="(value) => onSelectChange('sourceCodeLineNumbers', value)"
/>
</template>
</compound>
</div>
Expand Down Expand Up @@ -225,6 +230,7 @@ const {
hideQuickInsertHint,
hideLinkPopup,
autoCheck,
sourceCodeLineNumbers,
autoNormalizeLineEndings,
wrapCodeBlocks,
editorLineWidth,
Expand Down
2 changes: 2 additions & 0 deletions packages/desktop/src/renderer/src/store/preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export interface PreferencesState {
codeFontSize: number
codeFontFamily: string
codeBlockLineNumbers: boolean
sourceCodeLineNumbers: boolean
trimUnnecessaryCodeBlockEmptyLines: boolean
wrapCodeBlocks: boolean
editorLineWidth: string
Expand Down Expand Up @@ -163,6 +164,7 @@ export const usePreferencesStore = defineStore('preferences', {
codeFontSize: 14,
codeFontFamily: 'DejaVu Sans Mono',
codeBlockLineNumbers: false,
sourceCodeLineNumbers: true,
trimUnnecessaryCodeBlockEmptyLines: true,
wrapCodeBlocks: false,
editorLineWidth: '',
Expand Down
4 changes: 3 additions & 1 deletion packages/desktop/static/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@
"codeFontSize": "Schriftgröße im Codeblock, der Bereich ist 12 ~ 18",
"codeFontFamily": "Schriftfamilie im Codeblock",
"codeBlockLineNumbers": "Ob Zeilennummern angezeigt werden sollen",
"sourceCodeLineNumbers": "Zeilennummern im Quellcode-Modus anzeigen",
"trimUnnecessaryCodeBlockEmptyLines": "Leere Zeilen am Anfang und Ende des Codeblocks entfernen",
"autoPairBracket": "Automatische Klammern beim Bearbeiten",
"autoPairMarkdownSyntax": "Markdown-Syntax automatisch vervollständigen",
Expand Down Expand Up @@ -562,7 +563,8 @@
"hideLinkPopup": "Link-Popup ausblenden",
"autoCheck": "Automatische Überprüfung",
"autoNormalizeLineEndings": "Zeilenenden beim Öffnen automatisch auf LF normalisieren",
"wrapCodeBlocks": "Code-Blöcke umbrechen"
"wrapCodeBlocks": "Code-Blöcke umbrechen",
"sourceCodeLineNumbers": "Zeilennummern im Quellcode-Modus anzeigen"
}
},
"image": {
Expand Down
4 changes: 3 additions & 1 deletion packages/desktop/static/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@
"codeFontSize": "Font size in code Block, the range is 12 ~ 18",
"codeFontFamily": "Font family used in code block",
"codeBlockLineNumbers": "Whether to show the line numbers",
"sourceCodeLineNumbers": "Show line numbers in source code mode",
"trimUnnecessaryCodeBlockEmptyLines": "Trim the beginning and ending empty lines in code block",
"autoPairBracket": "Automatically brackets when editing",
"autoPairMarkdownSyntax": "Autocomplete markdown syntax",
Expand Down Expand Up @@ -562,7 +563,8 @@
"hideLinkPopup": "Hide link popup",
"autoCheck": "Auto check",
"autoNormalizeLineEndings": "Auto-normalize line endings to LF on open",
"wrapCodeBlocks": "Wrap code blocks"
"wrapCodeBlocks": "Wrap code blocks",
"sourceCodeLineNumbers": "Show line numbers in source code mode"
}
},
"image": {
Expand Down
4 changes: 3 additions & 1 deletion packages/desktop/static/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@
"codeFontSize": "Tamaño de fuente en bloque de código, el rango es 12 ~ 18",
"codeFontFamily": "Familia de fuente utilizada en bloque de código",
"codeBlockLineNumbers": "Si mostrar los números de línea",
"sourceCodeLineNumbers": "Mostrar números de línea en el modo código fuente",
"trimUnnecessaryCodeBlockEmptyLines": "Recortar las líneas vacías del principio y final en bloque de código",
"autoPairBracket": "Paréntesis automáticos al editar",
"autoPairMarkdownSyntax": "Autocompletar sintaxis de markdown",
Expand Down Expand Up @@ -562,7 +563,8 @@
"hideLinkPopup": "Ocultar popup de enlace",
"autoCheck": "Verificación automática",
"autoNormalizeLineEndings": "Normalizar automáticamente los finales de línea a LF al abrir",
"wrapCodeBlocks": "Ajustar bloques de código"
"wrapCodeBlocks": "Ajustar bloques de código",
"sourceCodeLineNumbers": "Mostrar números de línea en el modo código fuente"
}
},
"image": {
Expand Down
4 changes: 3 additions & 1 deletion packages/desktop/static/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@
"codeFontSize": "Taille de police dans le bloc de code, la plage est de 12 ~ 18",
"codeFontFamily": "Famille de police utilisée dans le bloc de code",
"codeBlockLineNumbers": "Afficher les numéros de ligne",
"sourceCodeLineNumbers": "Afficher les numéros de ligne en mode code source",
"trimUnnecessaryCodeBlockEmptyLines": "Supprimer les lignes vides au début et à la fin du bloc de code",
"autoPairBracket": "Parenthèses automatiques lors de l'édition",
"autoPairMarkdownSyntax": "Complétion automatique de la syntaxe markdown",
Expand Down Expand Up @@ -562,7 +563,8 @@
"hideLinkPopup": "Masquer la popup de lien",
"autoCheck": "Vérification automatique",
"autoNormalizeLineEndings": "Normaliser automatiquement les fins de ligne en LF à l'ouverture",
"wrapCodeBlocks": "Retour à la ligne des blocs de code"
"wrapCodeBlocks": "Retour à la ligne des blocs de code",
"sourceCodeLineNumbers": "Afficher les numéros de ligne en mode code source"
}
},
"image": {
Expand Down
4 changes: 3 additions & 1 deletion packages/desktop/static/locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@
"codeFontSize": "コードブロックのフォントサイズ、範囲は 12〜18",
"codeFontFamily": "コードブロックで使用されるフォントファミリー",
"codeBlockLineNumbers": "行番号を表示するかどうか",
"sourceCodeLineNumbers": "ソースコードモードで行番号を表示",
"trimUnnecessaryCodeBlockEmptyLines": "コードブロックの最初と最後の空行をトリミング",
"autoPairBracket": "編集時に括弧を自動で閉じる",
"autoPairMarkdownSyntax": "Markdown 構文の自動補完",
Expand Down Expand Up @@ -562,7 +563,8 @@
"hideLinkPopup": "リンクポップアップを隠す",
"autoCheck": "自動チェック",
"autoNormalizeLineEndings": "開くときに改行コードを自動的に LF へ統一",
"wrapCodeBlocks": "コードブロックを折り返し"
"wrapCodeBlocks": "コードブロックを折り返し",
"sourceCodeLineNumbers": "ソースコードモードで行番号を表示"
}
},
"image": {
Expand Down
4 changes: 3 additions & 1 deletion packages/desktop/static/locales/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@
"codeFontSize": "코드 블록의 글꼴 크기, 범위는 12~18",
"codeFontFamily": "코드 블록에서 사용되는 글꼴 패밀리",
"codeBlockLineNumbers": "줄 번호를 표시할지 여부",
"sourceCodeLineNumbers": "소스 코드 모드에서 줄 번호 표시",
"trimUnnecessaryCodeBlockEmptyLines": "코드 블록의 시작과 끝에 있는 빈 줄 제거",
"autoPairBracket": "편집 시 자동으로 괄호 쌍 만들기",
"autoPairMarkdownSyntax": "마크다운 구문 자동 완성",
Expand Down Expand Up @@ -562,7 +563,8 @@
"hideLinkPopup": "링크 팝업 숨기기",
"autoCheck": "자동 확인",
"autoNormalizeLineEndings": "열 때 줄 바꿈을 자동으로 LF로 정규화",
"wrapCodeBlocks": "코드 블록 줄바꿈"
"wrapCodeBlocks": "코드 블록 줄바꿈",
"sourceCodeLineNumbers": "소스 코드 모드에서 줄 번호 표시"
}
},
"image": {
Expand Down
4 changes: 3 additions & 1 deletion packages/desktop/static/locales/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@
"codeFontSize": "Lettergrootte in codeblokken (12-18)",
"codeFontFamily": "Lettertype voor codeblokken",
"codeBlockLineNumbers": "Regelnummers tonen",
"sourceCodeLineNumbers": "Regelnummers tonen in broncodeweergave",
"trimUnnecessaryCodeBlockEmptyLines": "Lege regels aan begin en einde van codeblokken verwijderen",
"autoPairBracket": "Automatisch haakjes aanvullen bij bewerken",
"autoPairMarkdownSyntax": "Markdown-syntax automatisch aanvullen",
Expand Down Expand Up @@ -562,7 +563,8 @@
"hideLinkPopup": "Link-popup verbergen",
"autoCheck": "Automatisch aanvinken",
"autoNormalizeLineEndings": "Regeleindes automatisch normaliseren naar LF bij openen",
"wrapCodeBlocks": "Codeblokken terugloopbaar"
"wrapCodeBlocks": "Codeblokken terugloopbaar",
"sourceCodeLineNumbers": "Regelnummers tonen in broncodeweergave"
}
},
"image": {
Expand Down
4 changes: 3 additions & 1 deletion packages/desktop/static/locales/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@
"codeFontSize": "Tamanho da fonte no bloco de código, o intervalo é 12 ~ 18",
"codeFontFamily": "Família de fonte usada no bloco de código",
"codeBlockLineNumbers": "Se mostrar os números de linha",
"sourceCodeLineNumbers": "Mostrar números de linha no modo código fonte",
"trimUnnecessaryCodeBlockEmptyLines": "Aparar as linhas vazias do início e fim no bloco de código",
"autoPairBracket": "Parênteses automáticos ao editar",
"autoPairMarkdownSyntax": "Autocompletar sintaxe markdown",
Expand Down Expand Up @@ -562,7 +563,8 @@
"hideLinkPopup": "Ocultar popup de link",
"autoCheck": "Verificação automática",
"autoNormalizeLineEndings": "Normalizar automaticamente finais de linha para LF ao abrir",
"wrapCodeBlocks": "Quebrar blocos de código"
"wrapCodeBlocks": "Quebrar blocos de código",
"sourceCodeLineNumbers": "Mostrar números de linha no modo código fonte"
}
},
"image": {
Expand Down
4 changes: 3 additions & 1 deletion packages/desktop/static/locales/tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@
"codeFontSize": "Kod bloğundaki yazı tipi boyutu, aralık 12 ~ 18",
"codeFontFamily": "Kod bloğunda kullanılan yazı tipi ailesi",
"codeBlockLineNumbers": "Satır numaralarının gösterilip gösterilmeyeceği",
"sourceCodeLineNumbers": "Kaynak kod modunda satır numaralarını göster",
"trimUnnecessaryCodeBlockEmptyLines": "Kod bloğundaki baştaki ve sondaki boş satırları kırp",
"autoPairBracket": "Düzenlerken parantezleri otomatik tamamla",
"autoPairMarkdownSyntax": "Markdown söz dizimini otomatik tamamla",
Expand Down Expand Up @@ -562,7 +563,8 @@
"hideLinkPopup": "Bağlantı açılır penceresini gizle",
"autoCheck": "Otomatik işaretle",
"autoNormalizeLineEndings": "Açılışta satır sonlarını LF'ye otomatik normalleştir",
"wrapCodeBlocks": "Kod bloklarını kaydır"
"wrapCodeBlocks": "Kod bloklarını kaydır",
"sourceCodeLineNumbers": "Kaynak kod modunda satır numaralarını göster"
}
},
"image": {
Expand Down
4 changes: 3 additions & 1 deletion packages/desktop/static/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@
"codeFontSize": "代码块中的字体大小,范围是 12 ~ 18",
"codeFontFamily": "代码块中使用的字体系列",
"codeBlockLineNumbers": "是否显示行号",
"sourceCodeLineNumbers": "在源码模式中显示行号",
"trimUnnecessaryCodeBlockEmptyLines": "修剪代码块开头和结尾的空行",
"autoPairBracket": "编辑时自动配对括号",
"autoPairMarkdownSyntax": "自动完成 Markdown 语法",
Expand Down Expand Up @@ -562,7 +563,8 @@
"hideLinkPopup": "隐藏链接弹出窗口",
"autoCheck": "自动检查",
"autoNormalizeLineEndings": "打开时自动将行尾规范化为 LF",
"wrapCodeBlocks": "换行代码块"
"wrapCodeBlocks": "换行代码块",
"sourceCodeLineNumbers": "在源码模式中显示行号"
}
},
"image": {
Expand Down
4 changes: 3 additions & 1 deletion packages/desktop/static/locales/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@
"codeFontSize": "程式碼區塊中的字型大小,範圍是 12 ~ 18",
"codeFontFamily": "程式碼區塊中使用的字型系列",
"codeBlockLineNumbers": "是否顯示行號",
"sourceCodeLineNumbers": "在原始碼模式中顯示行號",
"trimUnnecessaryCodeBlockEmptyLines": "修剪程式碼區塊開頭和結尾的空行",
"autoPairBracket": "編輯時自動配對括號",
"autoPairMarkdownSyntax": "自動完成 Markdown 語法",
Expand Down Expand Up @@ -562,7 +563,8 @@
"hideLinkPopup": "隱藏連結彈出視窗",
"autoCheck": "自動檢查",
"autoNormalizeLineEndings": "開啟時自動將行尾標準化為 LF",
"wrapCodeBlocks": "換行程式碼區塊"
"wrapCodeBlocks": "換行程式碼區塊",
"sourceCodeLineNumbers": "在原始碼模式中顯示行號"
}
},
"image": {
Expand Down
1 change: 1 addition & 0 deletions packages/desktop/static/preference.json
Loading
Loading