-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
foldGutter Addon not working #172
Comments
related to #145 @scttcper did you study my proposal (#145 (comment)) ? |
@johaven if you make a pr i'll consider it. It is a pretty decent sized breaking change. |
or we could ship two versions of the component that load differently? Could pull the require statement into a loadCodemirror() and then extend the class and overwrite just that part of the class. |
i made some tests, the simplest way to avoid a breaking change is to check if CodeMirror is loaded globally (via the scripts tag) and apply a simple condition like this: codemirror component ...
declare var CodeMirror: any
...
codeMirror: EditorFromTextArea
_codeMirror: any // variable where we store the global lib
...
constructor(private _differs: KeyValueDiffers, private _ngZone: NgZone) {
this._codeMirror = CodeMirror ? CodeMirror : require('codemirror')
}
...
ngAfterViewInit() {
this.codeMirror = this._codeMirror.fromTextArea(this.ref.nativeElement, this._options)
... It gives the possibility to access the library (global or not) directly by importing the child's view. To make it cleaner I would prefer to store the instance in the this.codeMirror attribute, and create a this.textArea attribute but that would cause a breaking change. We need in some cases to access the textArea element. A component example, watch especially the ngAfterViewInit part : @Component({
template: `
<ngx-codemirror #CodeMirror [(ngModel)]="content" [options]=options></ngx-codemirror>
`
})
export class FilesViewerTextComponent implements OnInit, AfterViewInit {
@ViewChild('CodeMirror') ref: any
.....
private readonly modeUrl = '/static/assets/codemirror/mode/%N/%N.js'
public content: string
public options: any = {lineNumbers: true, readOnly: true, theme: 'material', mode: 'null'}
private mode: string = null
ngOnInit() {
this.ref._codeMirror.modeURL = this.modeUrl
const detectedMode = this.ref._codeMirror.findModeByFileName(this.file.name)
if (detectedMode) {
this.mode = detectedMode.mode
this.http.get(this.fileUrl, {responseType: 'text'}).subscribe((data: string) => this.content = data)
}
}
ngAfterViewInit() {
if (this.mode) {
this.ref._codeMirror.autoLoadMode(this.ref.codeMirror, this.mode)
this.ref.codeMirror.setOption('mode', this.mode)
}
}
} There is just to document the case where we use addons not related to the textArea part and the fact that we have to put the library in the script part of Angular.json if we want to use them. |
@scttcper is this solution right for you? |
v2.0.0 should handle this use case, however i also wrapped in the update to angular 8 with the breaking change.
|
I'm able to use fold gutter in json but unable to use it when it comes to XML. Any thoughts on this? |
Can you provide your example where you got fold gutter working on JSON? |
I'm having the same problem as @PhilippRoessner, addons that affects the textArea doesn't work, the only way to make loadMode works was following @johaven setup, adding imports to angular.json. For example foldGutter does not show. Do you guys know how to make it work? //angular.json |
closing in favor of #145 |
I try to use the foldgutter addon but I can't see any gutters
I have added the addonscripts and styles to my angular.json - scripts and styles section:
I also added the gutter settings in my options-property in my component:
unfortunetly I can't see the gutter:
![grafik](https://user-images.githubusercontent.com/6959716/56351408-555f2700-61cd-11e9-9402-27bc6244a9af.png)
The text was updated successfully, but these errors were encountered: