Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1668a47

Browse files
committedDec 23, 2023
fix: tabs if already indented
1 parent 3cf0d6b commit 1668a47

File tree

3 files changed

+29
-13
lines changed

3 files changed

+29
-13
lines changed
 

‎src/components/MarkdownContent.vue

+18-8
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@
22
<!-- eslint-disable vue/no-v-html -->
33
<div
44
class="markdown-content"
5+
:class="`mode-${mode}`"
56
v-html="markdownContent"
67
/>
78
<!-- eslint-enable vue/no-v-html -->
89
</template>
910

1011
<script setup lang="ts">
11-
import { ref, watch } from 'vue'
12+
import { ref, watch, inject } from 'vue'
13+
import type { Ref } from 'vue'
14+
import { MODE_INJECTION_KEY } from '@/injection-keys'
15+
import type { MarkdownMode } from '@/types'
16+
17+
const mode: Ref<MarkdownMode> = inject(MODE_INJECTION_KEY, ref('read'))
1218
1319
const props = defineProps({
1420
content: {
@@ -39,11 +45,14 @@ $header-anchor-offset-top: calc(var(--kui-space-50, $kui-space-50) + 2px);
3945
font-weight: var(--kui-font-weight-regular, $kui-font-weight-regular);
4046
line-height: var(--kui-line-height-40, $kui-line-height-40);
4147
margin: 0;
42-
// max-width: 900px;
43-
padding: 0 var(--kui-space-70, $kui-space-70);
44-
width: calc(100% - (#{$kui-space-70} * 2)); // 100% width minus 2x padding
48+
padding: var(--kui-space-40, $kui-space-40) var(--kui-space-70, $kui-space-70);
4549
word-wrap: break-word;
4650
51+
&.mode-read {
52+
// Remove left and right padding in read mode
53+
padding: var(--kui-space-0, $kui-space-0);
54+
}
55+
4756
:deep() {
4857
font-size: var(--kui-font-size-40, $kui-font-size-40);
4958
line-height: var(--kui-line-height-40, $kui-line-height-40);
@@ -68,9 +77,10 @@ $header-anchor-offset-top: calc(var(--kui-space-50, $kui-space-50) + 2px);
6877
transition: opacity 0.2s ease-in-out;
6978
user-select: none;
7079
71-
&:hover {
72-
opacity: 1;
73-
}
80+
// TODO: Re-enable opacity and add left padding to `.markdown-content` if you want to see the header links on hover
81+
// &:hover {
82+
// opacity: 1;
83+
// }
7484
}
7585
7686
&:hover {
@@ -106,7 +116,7 @@ $header-anchor-offset-top: calc(var(--kui-space-50, $kui-space-50) + 2px);
106116
border-radius: var(--kui-border-radius-40, $kui-border-radius-40);
107117
font-family: var(--kui-font-family-code, $kui-font-family-code);
108118
font-size: var(--kui-font-size-30, $kui-font-size-30);
109-
line-height: var(--kui-line-height-50, $kui-line-height-50);
119+
line-height: var(--kui-line-height-30, $kui-line-height-30);
110120
margin: var(--kui-space-0, $kui-space-0);
111121
overflow-wrap: break-word;
112122
overflow-x: auto;

‎src/components/toolbar/MarkdownToolbar.vue

+1-3
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
</div>
3434

3535
<template v-if="editable && mode !== 'read'">
36-
<div class="toolbar-divider" />
37-
3836
<InfoTooltip
3937
v-for="option in formatOptions"
4038
:key="option.label"
@@ -176,7 +174,7 @@ import type { MarkdownMode, FormatOption, TemplateOption, InlineFormat, Markdown
176174
import IconButton from '@/components/toolbar/IconButton.vue'
177175
import InfoTooltip from '@/components/toolbar/InfoTooltip.vue'
178176
import TooltipShortcut from '@/components/toolbar/TooltipShortcut.vue'
179-
import { BoldIcon, ItalicIcon, UnderlineIcon, StrikethroughIcon, SubscriptIcon, SuperscriptIcon, MarkIcon, CodeIcon, CodeblockIcon, TableIcon, TasklistIcon, ListUnorderedIcon, ListOrderedIcon, MarkdownIcon, HtmlIcon, BlockquoteIcon, ExpandIcon, CollapseIcon } from '@kong/icons'
177+
import { BoldIcon, ItalicIcon, UnderlineIcon, StrikethroughIcon, /* SubscriptIcon, SuperscriptIcon, MarkIcon, */ CodeIcon, CodeblockIcon, TableIcon, TasklistIcon, ListUnorderedIcon, ListOrderedIcon, MarkdownIcon, HtmlIcon, BlockquoteIcon, ExpandIcon, CollapseIcon } from '@kong/icons'
180178
181179
const mode: Ref<MarkdownMode> = inject(MODE_INJECTION_KEY, ref('read'))
182180
const editable: Ref<boolean> = inject(EDITABLE_INJECTION_KEY, ref(false))

‎src/composables/useMarkdownActions.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -481,14 +481,22 @@ export default function useMarkdownActions(
481481
}
482482
}
483483

484+
let indentationSpaces = ''
485+
// If newline template is not needed, check if we should keep the indentation level
486+
if (newLineContent === NEW_LINE_CHARACTER) {
487+
Array.from(Array(lastLine.length - lastLine.trimStart().length).keys()).forEach(() => (indentationSpaces += ' '))
488+
}
489+
484490
// Update the raw markdown content
485-
rawMarkdown.value = removeNewLineTemplate ? rawMarkdown.value.substring(0, selectedText.start - lastLine.length) + rawMarkdown.value.substring(selectedText.end) : startText + newLineContent + rawMarkdown.value.substring(selectedText.end)
491+
rawMarkdown.value = removeNewLineTemplate
492+
? rawMarkdown.value.substring(0, selectedText.start - lastLine.length) + rawMarkdown.value.substring(selectedText.end)
493+
: (startText + newLineContent + indentationSpaces + rawMarkdown.value.substring(selectedText.end))
486494

487495
// Always focus back on the textarea
488496
await focusTextarea()
489497

490498
// Update the cursor position
491-
textarea.selectionEnd = removeNewLineTemplate ? selectedText.start - templateLength : selectedText.start + newLineContent.length
499+
textarea.selectionEnd = removeNewLineTemplate ? selectedText.start - templateLength : selectedText.start + newLineContent.length + indentationSpaces.length
492500
} catch (err) {
493501
console.warn('insertNewLine', err)
494502
}

0 commit comments

Comments
 (0)
Please sign in to comment.