A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/gorhill/uBlock/commit/e44a568278678e04b508c2bc1b8a94a2c54b848c below:

Add CoreMirror's code-folding ability to list editor/viewer · gorhill/uBlock@e44a568 · GitHub

32 32 33 33

const redirectNames = new Map();

34 34

const scriptletNames = new Map();

35 -

const preparseDirectiveTokens = new Set();

35 +

const preparseDirectiveTokens = new Map();

36 36

const preparseDirectiveHints = [];

37 37 38 38

/******************************************************************************/

@@ -44,8 +44,8 @@ CodeMirror.defineMode('ubo-static-filtering', function() {

44 44

if ( StaticFilteringParser instanceof Object === false ) { return; }

45 45

const parser = new StaticFilteringParser({ interactive: true });

46 46 47 -

const rePreparseDirectives = /^!#(?:if|endif|include)\b/;

48 -

const rePreparseIfDirective = /^(!#if !?)(.+)$/;

47 +

const rePreparseDirectives = /^!#(?:if|endif|include )\b/;

48 +

const rePreparseIfDirective = /^(!#if ?)(.*)$/;

49 49

let parserSlot = 0;

50 50

let netOptionValueMode = false;

51 51

@@ -60,17 +60,28 @@ CodeMirror.defineMode('ubo-static-filtering', function() {

60 60

return 'variable strong';

61 61

}

62 62

if ( stream.pos < match[1].length ) {

63 -

stream.pos = match[1].length;

63 +

stream.pos += match[1].length;

64 64

return 'variable strong';

65 65

}

66 66

stream.skipToEnd();

67 -

if (

68 -

preparseDirectiveTokens.size === 0 ||

69 -

preparseDirectiveTokens.has(match[2].trim())

70 -

) {

71 -

return 'variable strong';

67 +

if ( match[1].endsWith(' ') === false ) {

68 +

return 'error strong';

69 +

}

70 +

if ( preparseDirectiveTokens.size === 0 ) {

71 +

return 'positive strong';

72 +

}

73 +

let token = match[2];

74 +

const not = token.startsWith('!');

75 +

if ( not ) {

76 +

token = token.slice(1);

77 +

}

78 +

if ( preparseDirectiveTokens.has(token) === false ) {

79 +

return 'error strong';

72 80

}

73 -

return 'error strong';

81 +

if ( not !== preparseDirectiveTokens.get(token) ) {

82 +

return 'positive strong';

83 +

}

84 +

return 'negative strong';

74 85

};

75 86 76 87

const colorExtHTMLPatternSpan = function(stream) {

@@ -289,8 +300,8 @@ CodeMirror.defineMode('ubo-static-filtering', function() {

289 300

scriptletNames.set(name.slice(0, -3), displayText);

290 301

}

291 302

}

292 -

details.preparseDirectiveTokens.forEach(a => {

293 -

preparseDirectiveTokens.add(a);

303 +

details.preparseDirectiveTokens.forEach(([ a, b ]) => {

304 +

preparseDirectiveTokens.set(a, b);

294 305

});

295 306

preparseDirectiveHints.push(...details.preparseDirectiveHints);

296 307

initHints();

@@ -471,6 +482,63 @@ const initHints = function() {

471 482 472 483

/******************************************************************************/

473 484 485 +

CodeMirror.registerHelper('fold', 'ubo-static-filtering', (( ) => {

486 + 487 +

const foldIfEndif = function(startLineNo, startLine, cm) {

488 +

const lastLineNo = cm.lastLine();

489 +

let endLineNo = startLineNo;

490 +

let depth = 1;

491 +

while ( endLineNo < lastLineNo ) {

492 +

endLineNo += 1;

493 +

const line = cm.getLine(endLineNo);

494 +

if ( line.startsWith('!#endif') ) {

495 +

depth -= 1;

496 +

if ( depth === 0 ) {

497 +

return {

498 +

from: CodeMirror.Pos(startLineNo, startLine.length),

499 +

to: CodeMirror.Pos(endLineNo, 0)

500 +

};

501 +

}

502 +

}

503 +

if ( line.startsWith('!#if') ) {

504 +

depth += 1;

505 +

}

506 +

}

507 +

};

508 + 509 +

const foldInclude = function(startLineNo, startLine, cm) {

510 +

const lastLineNo = cm.lastLine();

511 +

let endLineNo = startLineNo + 1;

512 +

if ( endLineNo >= lastLineNo ) { return; }

513 +

if ( cm.getLine(endLineNo).startsWith('! >>>>>>>> ') === false ) {

514 +

return;

515 +

}

516 +

while ( endLineNo < lastLineNo ) {

517 +

endLineNo += 1;

518 +

const line = cm.getLine(endLineNo);

519 +

if ( line.startsWith('! <<<<<<<< ') ) {

520 +

return {

521 +

from: CodeMirror.Pos(startLineNo, startLine.length),

522 +

to: CodeMirror.Pos(endLineNo, line.length)

523 +

};

524 +

}

525 +

}

526 +

};

527 + 528 +

return function(cm, start) {

529 +

const startLineNo = start.line;

530 +

const startLine = cm.getLine(startLineNo);

531 +

if ( startLine.startsWith('!#if') ) {

532 +

return foldIfEndif(startLineNo, startLine, cm);

533 +

}

534 +

if ( startLine.startsWith('!#include ') ) {

535 +

return foldInclude(startLineNo, startLine, cm);

536 +

}

537 +

};

538 +

})());

539 + 540 +

/******************************************************************************/

541 + 474 542

// <<<<< end of local scope

475 543

}

476 544

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4