import { combinedRegex , REGEX } from 'shared/Regex' ; const acequire = ( require ( 'brace' ) as any ) . acequire ; const oop = acequire ( 'ace/lib/oop' ) ; const { Range } = acequire ( 'ace/range' ) ; const TextMode = ( acequire ( 'ace/mode/text' ) as any ) . Mode ; const MatchingBraceOutdent = ( acequire ( 'ace/mode/matching_brace_outdent' ) as any ) . MatchingBraceOutdent ; const MarkdownHighlightRules = ( acequire ( 'ace/mode/markdown_highlight_rules' ) as any ) . MarkdownHighlightRules ; const QDLHighlightRules = function ( ) { this . $rules = new MarkdownHighlightRules ( ) . getRules ( ) ; const listblock = this . $rules . listblock ; for ( const r in listblock ) { if ( listblock [ r ] . token === 'empty_line' ) { listblock [ r ] . regex = /^\s*$/ ; break ; } } this . $rules . start = [ { token : 'comment' , regex : /^\s*(\/\/.*)|(\/\*.*\*\/)/ , } , { token : 'variable' , regex : combinedRegex ( [ REGEX . OP , REGEX . TRIGGER , REGEX . ID , ] ) , } , { token : 'heading' , regex : /^\s*((> .*)|(_.*_))/ , } , { token : 'list' , regex : /^\s*[*+-]\s+.*/ , } , { token : 'string' , regex : combinedRegex ( [ REGEX . ART , REGEX . ICON , REGEX . NEWLINE , REGEX . BOLD_ASTERISKS , REGEX . BOLD_UNDERSCORES , REGEX . ITALIC_ASTERISKS , REGEX . ITALIC_UNDERSCORES , REGEX . STRIKETHROUGH , ] ) , } , { defaultToken : 'text.xml' , } , ] ; } ; oop . inherits ( QDLHighlightRules , MarkdownHighlightRules ) ; class QDLFoldMode { public static foldingStartMarkers = [ /(^\s*)(\* .*)/ , /(^\s*)(_.*_)/ , /(^\s*)(# .*)/ , ] ; public static foldingStartMarker = new RegExp ( QDLFoldMode . foldingStartMarkers . map ( ( x ) => x . source ) . join ( '|' ) ) ; private static getIndent ( line ) { let indent = 0 ; while ( line [ indent ] === ' ' ) { indent ++ ; } return indent ; } private static getImportance ( line ) { for ( let i = QDLFoldMode . foldingStartMarkers . length - 1 ; i >= 0 ; i -- ) { if ( line . match ( QDLFoldMode . foldingStartMarkers [ i ] ) ) { return i ; } } return - 1 ; } public getFoldWidget ( session , foldStyle , row ) { const line = session . getLine ( row ) ; return QDLFoldMode . foldingStartMarker . test ( line ) ? 'start' : '' ; } public getFoldWidgetRange ( session , foldStyle , row ) { let line = session . getLine ( row ) ; if ( ! line . match ( QDLFoldMode . foldingStartMarker ) ) { return ; } const startRow = row ; const startColumn = line . length ; const maxRow = session . getLength ( ) ; const startIndent = QDLFoldMode . getIndent ( line ) ; const startImportance = QDLFoldMode . getImportance ( line ) ; let endRow = maxRow ; for ( row += 1 ; row < maxRow ; row ++ ) { line = session . getLine ( row ) ; if ( QDLFoldMode . getIndent ( line ) <= startIndent && QDLFoldMode . getImportance ( line ) >= startImportance ) { endRow = row - 1 ; break ; } } return new Range ( startRow , startColumn , endRow , session . getLine ( endRow ) . length ) ; } } export const QDLMode = function ( ) { this . HighlightRules = QDLHighlightRules ; this . $outdent = new MatchingBraceOutdent ( ) ; this . foldingRules = new QDLFoldMode ( ) ; } ; oop . inherits ( QDLMode , TextMode ) ; ( function ( ) { this . lineCommentStart = '//' ; this . blockComment = { start : '/*' , end : '*/' } ; this . getNextLineIndent = function ( state , line , tab ) { const indent = this . $getIndent ( line ) ; if ( line . trim ( ) . startsWith ( '* ' ) ) { return ' \n' + indent + '  ' ; } return indent ; } ; this . checkOutdent = function ( state , line , input ) { return this . $outdent . checkOutdent ( line , input ) ; } ; this . autoOutdent = function ( state , doc , row ) { return this . $outdent . autoOutdent ( doc , row ) ; } ; } ) . call ( QDLMode . prototype ) ;