Skip to content

Commit 4a5fa81

Browse files
committed
feat: enable codemirror full screen editing by F11
1 parent 50cc41a commit 4a5fa81

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

pywebio/html/codemirror/addons.js

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pywebio/html/css/app.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,4 +277,11 @@ details[open]>summary {
277277
text-overflow: ellipsis;
278278
white-space: nowrap;
279279
display: inline-block !important;
280+
}
281+
282+
.CodeMirror-fullscreen {
283+
position: fixed;
284+
top: 0; left: 0; right: 0; bottom: 0;
285+
height: auto;
286+
z-index: 9;
280287
}

webiojs/src/models/input/textarea.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,16 @@ export class Textarea extends InputItem {
2424
'styleActiveLine': true, // 当前行背景高亮
2525
'matchBrackets': true, //括号匹配
2626
'lineWrapping': true, //自动换行
27-
'autoRefresh': true // https://codemirror.net/doc/manual.html#addon_autorefresh
27+
'autoRefresh': true, // https://codemirror.net/doc/manual.html#addon_autorefresh
28+
'extraKeys': {
29+
// Full Screen Editing, https://codemirror.net/demo/fullscreen.html
30+
"F11": function (cm: any) {
31+
cm.setOption("fullScreen", !cm.getOption("fullScreen"));
32+
},
33+
"Esc": function (cm: any) {
34+
if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false);
35+
}
36+
}
2837
};
2938

3039
constructor(spec: any, task_id: string, on_input_event: (event_name: string, input_item: InputItem) => void) {
@@ -62,7 +71,8 @@ export class Textarea extends InputItem {
6271
this.code_mirror_config[k] = that.spec.code[k];
6372

6473
// Get mode name by extension or MIME
65-
let mode_info = CodeMirror.findModeByExtension(spec.code.mode) || CodeMirror.findModeByMIME(spec.code.mode);
74+
let origin_mode = spec.code.mode || 'text/plain';
75+
let mode_info = CodeMirror.findModeByExtension(origin_mode) || CodeMirror.findModeByMIME(origin_mode);
6676
if (mode_info)
6777
this.code_mirror_config.mode = mode_info.mode;
6878

0 commit comments

Comments
 (0)