mirror of
				https://github.com/BookStackApp/BookStack.git
				synced 2025-11-04 13:31:45 +03:00 
			
		
		
		
	- Can now save a code block with Ctrl+Enter. - Codemirror will be in focus on popup show. - TinyMCE will get back focus on code save. For #1972
		
			
				
	
	
		
			46 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			46 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
import codeLib from "../services/code";
 | 
						|
 | 
						|
const methods = {
 | 
						|
    show() {
 | 
						|
        if (!this.editor) this.editor = codeLib.popupEditor(this.$refs.editor, this.language);
 | 
						|
        this.$refs.overlay.components.overlay.show(() => {
 | 
						|
            codeLib.updateLayout(this.editor);
 | 
						|
            this.editor.focus();
 | 
						|
        });
 | 
						|
    },
 | 
						|
    hide() {
 | 
						|
        this.$refs.overlay.components.overlay.hide();
 | 
						|
    },
 | 
						|
    updateEditorMode(language) {
 | 
						|
        codeLib.setMode(this.editor, language, this.editor.getValue());
 | 
						|
    },
 | 
						|
    updateLanguage(lang) {
 | 
						|
        this.language = lang;
 | 
						|
        this.updateEditorMode(lang);
 | 
						|
    },
 | 
						|
    open(code, language, callback) {
 | 
						|
        this.show();
 | 
						|
        this.updateEditorMode(language);
 | 
						|
        this.language = language;
 | 
						|
        codeLib.setContent(this.editor, code);
 | 
						|
        this.code = code;
 | 
						|
        this.callback = callback;
 | 
						|
    },
 | 
						|
    save() {
 | 
						|
        if (!this.callback) return;
 | 
						|
        this.callback(this.editor.getValue(), this.language);
 | 
						|
        this.hide();
 | 
						|
    }
 | 
						|
};
 | 
						|
 | 
						|
const data = {
 | 
						|
    editor: null,
 | 
						|
    language: '',
 | 
						|
    code: '',
 | 
						|
    callback: null
 | 
						|
};
 | 
						|
 | 
						|
export default {
 | 
						|
    methods,
 | 
						|
    data
 | 
						|
}; |