@@ -11,7 +11,7 @@ import {createRunLinterRulesOptions, RulesRunner} from './rules-runner';
1111import { LinterError } from './linter-error' ;
1212import { LintConfirmationModal } from './ui/modals/lint-confirmation-modal' ;
1313import { SettingTab } from './ui/settings' ;
14- import { urlRegex } from './utils/regex' ;
14+ import { escapeRegExp , urlRegex } from './utils/regex' ;
1515import { getTextInLanguage , LanguageStringKey , setLanguage } from './lang/helpers' ;
1616import { RuleAliasSuggest } from './cm6/rule-alias-suggester' ;
1717import { AfterFileChangeLintTimes , DEFAULT_SETTINGS , LinterSettings } from './settings-data' ;
@@ -215,6 +215,36 @@ export default class LinterPlugin extends Plugin {
215215 void this . pasteAsPlainText ( editor ) ;
216216 } ,
217217 } ) ;
218+
219+ this . addCommand ( {
220+ id : 'ignore-folder' ,
221+ name : getTextInLanguage ( 'commands.ignore-folder.name' ) ,
222+ icon : iconInfo . ignoreFolder . id ,
223+ editorCheckCallback : ( checking : boolean , _ , ctx ) => {
224+ if ( checking ) {
225+ if ( ctx && ctx . file && ctx . file instanceof TFile && ctx . file . parent ) {
226+ return ! ctx . file . parent . isRoot ( ) && ! this . settings . foldersToIgnore . includes ( ctx . file . parent . path ) ;
227+ }
228+
229+ return false ;
230+ }
231+
232+ void this . addFolderToIgnoreList ( ctx . file . parent ) ;
233+ } ,
234+ } ) ;
235+
236+ this . addCommand ( {
237+ id : 'ignore-file' ,
238+ name : getTextInLanguage ( 'commands.ignore-file.name' ) ,
239+ editorCheckCallback ( checking , _ , ctx ) {
240+ if ( checking && ctx . file ) {
241+ return that . isMarkdownFile ( ctx . file ) && ! that . shouldIgnoreFile ( ctx . file ) ;
242+ }
243+
244+ void this . addFileToIgnoreList ( ctx . file ) ;
245+ } ,
246+ icon : iconInfo . ignoreFile . id ,
247+ } ) ;
218248 }
219249
220250 registerEventsAndSaveCallback ( ) {
@@ -365,26 +395,43 @@ export default class LinterPlugin extends Plugin {
365395
366396 onMenuOpenCallback ( menu : Menu , file : TAbstractFile , _source : string ) {
367397 if ( file instanceof TFile && this . isMarkdownFile ( file ) ) {
368- menu . addItem ( ( item ) => {
369- item . setIcon ( iconInfo . file . id )
370- . setTitle ( getTextInLanguage ( 'commands.lint-file-pop-up-menu-text.name' ) )
371- . onClick ( ( ) => {
372- const activeFile = this . app . workspace . getActiveFile ( ) ;
373- const editor = this . getEditor ( ) ;
374- if ( activeFile === file && editor && editor . cm ) {
375- void this . runLinterEditor ( editor ) ;
376- } else {
377- void this . runLinterFile ( file ) ;
378- }
379- } ) ;
380- } ) ;
398+ if ( ! this . shouldIgnoreFile ( file ) ) {
399+ menu . addItem ( ( item ) => {
400+ item . setIcon ( iconInfo . file . id )
401+ . setTitle ( getTextInLanguage ( 'commands.lint-file-pop-up-menu-text.name' ) )
402+ . onClick ( ( ) => {
403+ const activeFile = this . app . workspace . getActiveFile ( ) ;
404+ const editor = this . getEditor ( ) ;
405+ if ( activeFile === file && editor && editor . cm ) {
406+ void this . runLinterEditor ( editor ) ;
407+ } else {
408+ void this . runLinterFile ( file ) ;
409+ }
410+ } ) ;
411+ } ) ;
412+
413+ menu . addItem ( ( item ) => {
414+ item . setIcon ( iconInfo . ignoreFile . id )
415+ . setTitle ( getTextInLanguage ( 'commands.ignore-file-pop-up-menu-text.name' ) )
416+ . onClick ( ( ) => {
417+ void this . addFileToIgnoreList ( file ) ;
418+ } ) ;
419+ } ) ;
420+ }
381421 } else if ( file instanceof TFolder ) {
382- menu . addItem ( ( item ) => {
383- item
384- . setTitle ( getTextInLanguage ( 'commands.lint-folder-pop-up-menu-text.name' ) )
385- . setIcon ( iconInfo . folder . id )
386- . onClick ( ( ) => this . createFolderLintModal ( file ) ) ;
387- } ) ;
422+ if ( ! this . settings . foldersToIgnore . includes ( file . path ) ) {
423+ menu . addItem ( ( item ) => {
424+ item . setTitle ( getTextInLanguage ( 'commands.lint-folder-pop-up-menu-text.name' ) )
425+ . setIcon ( iconInfo . folder . id )
426+ . onClick ( ( ) => this . createFolderLintModal ( file ) ) ;
427+ } ) ;
428+
429+ menu . addItem ( ( item ) => {
430+ item . setTitle ( getTextInLanguage ( 'commands.ignore-folder-pop-up-menu-text.name' ) )
431+ . setIcon ( iconInfo . ignoreFolder . id )
432+ . onClick ( ( ) => void this . addFolderToIgnoreList ( file ) ) ;
433+ } ) ;
434+ }
388435 }
389436 }
390437
@@ -1118,4 +1165,20 @@ export default class LinterPlugin extends Plugin {
11181165 this . activeFileChangeDebouncer . get ( file . path ) . originalText = newText ;
11191166 }
11201167 }
1168+
1169+ private async addFileToIgnoreList ( file : TFile ) {
1170+ this . settings . filesToIgnore . push ( {
1171+ match : '^' + escapeRegExp ( file . path ) + '$' ,
1172+ flags : '' ,
1173+ label : '' ,
1174+ } ) ;
1175+
1176+ await this . saveSettings ( ) ;
1177+ }
1178+
1179+ private async addFolderToIgnoreList ( folder : TFolder ) {
1180+ this . settings . foldersToIgnore . push ( folder . path ) ;
1181+
1182+ await this . saveSettings ( ) ;
1183+ }
11211184}
0 commit comments