Code Monkey home page Code Monkey logo

Comments (3)

Romgua avatar Romgua commented on September 27, 2024 6

I found a solution !
You just need to "refresh" the codemirror instance ;)
(So you no longer need to override CSS Class)

First in my component.html, I add #editor :

<codemirror #editor name="myCode" [(ngModel)]="code"
 [config]="{lineNumbers: true, theme: 'mdn-like', mode: 'lua', autofocus: true, height: '500px'}">
</codemirror>

Secondly in my component.ts, I declare a ViewChild :
@ViewChild('editor') editor:any;

(Don't forget to import it import { Component, OnInit, ViewChild } from '@angular/core';)

And finally, in the function which open the modal in my component.ts :

openModal() {
    let cm = this.editor.instance;
    setTimeout(function() {
        cm.refresh();
        
        // Set cursor to the end
        let posCursor = {line: 0, ch: 0};
        posCursor.line = cm.doc.children[0].lines.length-1;
        posCursor.ch = cm.doc.children[0].lines[posCursor.line].text.length;
        
        cm.doc.setCursor(posCursor);
    }, 200);

    this.modal.open('lg');
}

from ng2-codemirror.

AceTheNinja avatar AceTheNinja commented on September 27, 2024

I am facing the same problem any workaround?

from ng2-codemirror.

Romgua avatar Romgua commented on September 27, 2024

I have an error too with ng2-codemirror and ng2-bs3-modal.
I use this config : {lineNumbers: true, theme: 'mdn-like', mode: 'clike', height: '500px'}

Before clicking :
codemirror-modal-before-clicking

After clicking :
codemirror-modal-after-clicking

And when writing :
codemirror-modal-after-writing

**~~ EDIT ~~**
For the css issue I add 2 rules :

#my-modal .CodeMirror-sizer {
  margin-left: 39px !important;
}

#my-modal .cm-s-mdn-like .CodeMirror-gutters {
  width: 32px;
}

But I always need to click on the CodeMirror to display text, and also press a button on my keyboard to pass in editing mode (not readOnly).

from ng2-codemirror.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.