Skip to content

Commit cf324d9

Browse files
ehhcRokt33r
authored andcommitted
Add option to disable the automiatic deletion of un-referenced attachments -> might fix #3203
1 parent 857e755 commit cf324d9

File tree

5 files changed

+26
-7
lines changed

5 files changed

+26
-7
lines changed

browser/components/CodeEditor.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ export default class CodeEditor extends React.Component {
7070
storageKey,
7171
noteKey
7272
} = this.props
73-
debouncedDeletionOfAttachments(this.editor.getValue(), storageKey, noteKey)
73+
if (this.props.deleteUnusedAttachments === true) {
74+
debouncedDeletionOfAttachments(this.editor.getValue(), storageKey, noteKey)
75+
}
7476
}
7577
this.pasteHandler = (editor, e) => {
7678
e.preventDefault()
@@ -632,6 +634,9 @@ export default class CodeEditor extends React.Component {
632634
this.editor.addPanel(this.createSpellCheckPanel(), {position: 'bottom'})
633635
}
634636
}
637+
if (prevProps.deleteUnusedAttachments !== this.props.deleteUnusedAttachments) {
638+
this.editor.setOption('deleteUnusedAttachments', this.props.deleteUnusedAttachments)
639+
}
635640

636641
if (needRefresh) {
637642
this.editor.refresh()
@@ -1204,7 +1209,8 @@ CodeEditor.propTypes = {
12041209
autoDetect: PropTypes.bool,
12051210
spellCheck: PropTypes.bool,
12061211
enableMarkdownLint: PropTypes.bool,
1207-
customMarkdownLintConfig: PropTypes.string
1212+
customMarkdownLintConfig: PropTypes.string,
1213+
deleteUnusedAttachments: PropTypes.bool
12081214
}
12091215

12101216
CodeEditor.defaultProps = {
@@ -1219,5 +1225,6 @@ CodeEditor.defaultProps = {
12191225
spellCheck: false,
12201226
enableMarkdownLint: DEFAULT_CONFIG.editor.enableMarkdownLint,
12211227
customMarkdownLintConfig: DEFAULT_CONFIG.editor.customMarkdownLintConfig,
1222-
prettierConfig: DEFAULT_CONFIG.editor.prettierConfig
1228+
prettierConfig: DEFAULT_CONFIG.editor.prettierConfig,
1229+
deleteUnusedAttachments: DEFAULT_CONFIG.editor.deleteUnusedAttachments
12231230
}

browser/components/MarkdownEditor.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ class MarkdownEditor extends React.Component {
324324
enableMarkdownLint={config.editor.enableMarkdownLint}
325325
customMarkdownLintConfig={config.editor.customMarkdownLintConfig}
326326
prettierConfig={config.editor.prettierConfig}
327+
deleteUnusedAttachments={config.editor.deleteUnusedAttachments}
327328
/>
328329
<MarkdownPreview styleName={this.state.status === 'PREVIEW'
329330
? 'preview'

browser/components/MarkdownSplitEditor.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ class MarkdownSplitEditor extends React.Component {
182182
switchPreview={config.editor.switchPreview}
183183
enableMarkdownLint={config.editor.enableMarkdownLint}
184184
customMarkdownLintConfig={config.editor.customMarkdownLintConfig}
185+
deleteUnusedAttachments={config.editor.deleteUnusedAttachments}
185186
/>
186187
<div styleName='slider' style={{left: this.state.codeEditorWidthInPercent + '%'}} onMouseDown={e => this.handleMouseDown(e)} >
187188
<div styleName='slider-hitbox' />

browser/main/lib/ConfigManager.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ export const DEFAULT_CONFIG = {
7575
"tabWidth": 4,
7676
"semi": false,
7777
"singleQuote": true
78-
}`
79-
78+
}`,
79+
deleteUnusedAttachments: true
8080
},
8181
preview: {
8282
fontSize: '14',

browser/main/modals/PreferencesModal/UiTab.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ class UiTab extends React.Component {
111111
enableSmartPaste: this.refs.enableSmartPaste.checked,
112112
enableMarkdownLint: this.refs.enableMarkdownLint.checked,
113113
customMarkdownLintConfig: this.customMarkdownLintConfigCM.getCodeMirror().getValue(),
114-
prettierConfig: this.prettierConfigCM.getCodeMirror().getValue()
115-
114+
prettierConfig: this.prettierConfigCM.getCodeMirror().getValue(),
115+
deleteUnusedAttachments: this.refs.deleteUnusedAttachments.checked
116116
},
117117
preview: {
118118
fontSize: this.refs.previewFontSize.value,
@@ -618,6 +618,16 @@ class UiTab extends React.Component {
618618
{i18n.__('Enable spellcheck - Experimental feature!! :)')}
619619
</label>
620620
</div>
621+
<div styleName='group-checkBoxSection'>
622+
<label>
623+
<input onChange={(e) => this.handleUIChange(e)}
624+
checked={this.state.config.editor.deleteUnusedAttachments}
625+
ref='deleteUnusedAttachments'
626+
type='checkbox'
627+
/>&nbsp;
628+
{i18n.__('Delete attachments, that are not referenced in the text anymore')}
629+
</label>
630+
</div>
621631

622632
<div styleName='group-section'>
623633
<div styleName='group-section-label'>

0 commit comments

Comments
 (0)