Skip to content

Commit 258cbab

Browse files
committed
Disable inline issue parsing when prefix empty #47
1 parent b2defcc commit 258cbab

File tree

2 files changed

+27
-20
lines changed

2 files changed

+27
-20
lines changed

src/rendering/inlineIssueViewPlugin.ts

+21-17
Original file line numberDiff line numberDiff line change
@@ -72,24 +72,28 @@ let jiraTagMatchDecorator: IMatchDecoratorRef = { ref: null }
7272
let jiraUrlMatchDecorator: IMatchDecoratorRef = { ref: null }
7373

7474
function buildMatchDecorators() {
75-
jiraTagMatchDecorator.ref = new MatchDecorator({
76-
regexp: new RegExp(`${SettingsData.inlineIssuePrefix}(${COMPACT_SYMBOL}?)([A-Z0-9]+-[0-9]+)`, 'g'),
77-
decoration: (match: RegExpExecArray, view: EditorView, pos: number) => {
78-
const compact = !!match[1]
79-
const key = match[2]
80-
const tagLength = match[0].length
81-
if (!isEditorInLivePreviewMode(view) || isCursorInsideTag(view, pos, tagLength) || isSelectionContainsTag(view, pos, tagLength)) {
82-
return Decoration.mark({
83-
tagName: 'div',
84-
class: 'HyperMD-codeblock HyperMD-codeblock-bg jira-issue-inline-mark',
85-
})
86-
} else {
87-
return Decoration.replace({
88-
widget: new InlineIssueWidget(key, compact),
89-
})
75+
if (SettingsData.inlineIssuePrefix !== '') {
76+
jiraTagMatchDecorator.ref = new MatchDecorator({
77+
regexp: new RegExp(`${SettingsData.inlineIssuePrefix}(${COMPACT_SYMBOL}?)([A-Z0-9]+-[0-9]+)`, 'g'),
78+
decoration: (match: RegExpExecArray, view: EditorView, pos: number) => {
79+
const compact = !!match[1]
80+
const key = match[2]
81+
const tagLength = match[0].length
82+
if (!isEditorInLivePreviewMode(view) || isCursorInsideTag(view, pos, tagLength) || isSelectionContainsTag(view, pos, tagLength)) {
83+
return Decoration.mark({
84+
tagName: 'div',
85+
class: 'HyperMD-codeblock HyperMD-codeblock-bg jira-issue-inline-mark',
86+
})
87+
} else {
88+
return Decoration.replace({
89+
widget: new InlineIssueWidget(key, compact),
90+
})
91+
}
9092
}
91-
}
92-
})
93+
})
94+
} else {
95+
jiraTagMatchDecorator.ref = null
96+
}
9397

9498
if (SettingsData.inlineIssueUrlToTag) {
9599
const urls: string[] = []

src/settings.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { App, Notice, PluginSettingTab, Setting, TextComponent } from 'obsidian'
22
import { JiraClient } from './client/jiraClient'
3-
import { IJiraAutocompleteDataField, IJiraFieldSchema, IJiraIssueAccountSettings } from './client/jiraInterfaces'
3+
import { IJiraIssueAccountSettings } from './client/jiraInterfaces'
44
import JiraIssuePlugin from './main'
55
import { ESearchColumnsTypes, ISearchColumn, SEARCH_COLUMNS_DESCRIPTION } from './searchView'
66

@@ -456,13 +456,16 @@ export class JiraIssueSettingTab extends PluginSettingTab {
456456
await this.saveSettings()
457457
}))
458458

459-
new Setting(containerEl)
459+
const inlineIssuePrefixDesc = (prefix: string) => 'Prefix to use when rendering inline issues. Keep this field empty to disable this feature. '
460+
+ (prefix ? `Example: ${prefix}AAA-123` : 'Feature disabled.')
461+
const inlineIssuePrefixSetting = new Setting(containerEl)
460462
.setName('Inline issue prefix')
461-
.setDesc(`Prefix to use when rendering inline issues. Keep this field empty to disable this feature. Example: ${SettingsData.inlineIssuePrefix}AAA-123`)
463+
.setDesc(inlineIssuePrefixDesc(SettingsData.inlineIssuePrefix))
462464
.addText(text => text
463465
.setValue(SettingsData.inlineIssuePrefix)
464466
.onChange(async value => {
465467
SettingsData.inlineIssuePrefix = value
468+
inlineIssuePrefixSetting.setDesc(inlineIssuePrefixDesc(SettingsData.inlineIssuePrefix))
466469
await this.saveSettings()
467470
}))
468471
new Setting(containerEl)

0 commit comments

Comments
 (0)