1
- import {
2
- AfterViewInit ,
3
- Directive ,
4
- Input ,
5
- OnChanges ,
6
- Optional ,
7
- Self ,
8
- } from '@angular/core' ;
1
+ import { AfterViewInit , Directive , Input , OnChanges , Optional , Self , } from '@angular/core' ;
9
2
import { findPosition } from '../utils/utils' ;
10
3
import { CodeDemoEditorInjector } from '@codelab/code-demos/src/lib/code-demo-editor/code-demo-editor.injector' ;
11
4
import { MonacoConfigService } from '@codelab/code-demos/src/lib/shared/monaco-config.service' ;
12
5
import { editor } from 'monaco-editor' ;
6
+ import {
7
+ rangeToDecoration
8
+ } from '../../../../../../apps/codelab/src/app/admin/content/presentation-editor/wrappers/custom-component-editors/codelab-code-demo-console-editor/highlight-button/highlight-button.component' ;
13
9
import IEditorDecorationsCollection = editor . IEditorDecorationsCollection ;
14
- import { rangeToDecoration } from '../../../../../../apps/codelab/src/app/admin/content/presentation- editor/wrappers/custom-component-editors/codelab-code-demo-console-editor/highlight-button/highlight-button.component' ;
10
+ import IStandaloneCodeEditor = editor . IStandaloneCodeEditor ;
15
11
16
12
@Directive ( {
17
13
selector : '[codeDemoHighlight]' ,
18
14
} )
19
15
export class CodeDemoEditorHighlightDirective
20
- implements OnChanges , AfterViewInit
21
- {
16
+ implements OnChanges , AfterViewInit {
22
17
readonly decorators = [ ] ;
23
- private decorationsCollection ?: IEditorDecorationsCollection ;
24
18
@Input ( ) codeDemoHighlight ;
25
19
@Input ( ) ngModel ;
20
+ hasZone = false ;
21
+ private decorationsCollection ?: IEditorDecorationsCollection ;
26
22
27
23
constructor (
28
24
@Self ( ) @Optional ( ) private editorInjector : CodeDemoEditorInjector ,
29
25
readonly monacoConfigService : MonacoConfigService
30
- ) { }
26
+ ) {
27
+ }
31
28
32
29
ngAfterViewInit ( ) {
33
30
this . highlight ( ) ;
@@ -37,6 +34,40 @@ export class CodeDemoEditorHighlightDirective
37
34
} , 1000 ) ;
38
35
}
39
36
37
+ // addZone(editor: IStandaloneCodeEditor) {
38
+ // if (this.hasZone) {
39
+ // return;
40
+ // }
41
+ // this.hasZone = true;
42
+ //
43
+ // editor.changeViewZones(function (changeAccessor) {
44
+ // var domNode = document.createElement('div');
45
+ // domNode.style.background = 'transparent';
46
+ // domNode.innerHTML = `
47
+ // <div style="display: inline-block; padding: 8px; border-radius: 8px; background: #ffcbd5; border: 1px #ddd solid">This is a text lol</div>
48
+ // `;
49
+ //
50
+ // changeAccessor.addZone({
51
+ // afterLineNumber: 1,
52
+ // heightInLines: 2,
53
+ // domNode: domNode
54
+ // });
55
+ //
56
+ //
57
+ // var domNode2 = document.createElement('div');
58
+ // domNode2.style.background = 'transparent';
59
+ // domNode2.innerHTML = `
60
+ // <div style="display: inline-block; font-family: 'Helvetica Neue';">This is a text lol</div>
61
+ // `;
62
+ //
63
+ // changeAccessor.addZone({
64
+ // afterLineNumber: 0,
65
+ // heightInLines: 2,
66
+ // domNode: domNode2
67
+ // });
68
+ // });
69
+ // }
70
+
40
71
highlight ( ) {
41
72
if ( ! this . editorInjector ) {
42
73
return ;
@@ -74,9 +105,9 @@ export class CodeDemoEditorHighlightDirective
74
105
} else {
75
106
const decorations = this . codeDemoHighlight
76
107
. map ( ( match ) =>
77
- typeof match !== 'string' && match . match ? match : { match }
108
+ typeof match !== 'string' && match . match ? match : { match}
78
109
)
79
- . reduce ( ( ranges , { match, className } ) => {
110
+ . reduce ( ( ranges , { match, className} ) => {
80
111
let range : [ number , number , number , number ] ;
81
112
if ( match . endColumn ) {
82
113
range = [
@@ -88,13 +119,13 @@ export class CodeDemoEditorHighlightDirective
88
119
} else {
89
120
const position = findPosition ( code , match ) ;
90
121
91
- const { indexStart, lineStart, indexEnd, lineEnd } = position ;
122
+ const { indexStart, lineStart, indexEnd, lineEnd} = position ;
92
123
range = [ lineStart , indexStart , lineEnd , indexEnd ] ;
93
124
}
94
125
95
126
ranges . push ( {
96
127
range : new this . monacoConfigService . monaco . Range ( ...range ) ,
97
- options : { inlineClassName : className || 'highlighted-code' } ,
128
+ options : { inlineClassName : className || 'highlighted-code' } ,
98
129
} ) ;
99
130
100
131
return ranges ;
0 commit comments