地质所 沉降监测网建设项目
zmk
2024-05-15 9e3afc6d0fa514f986d3fea40fa23124e6fb5070
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<!DOCTYPE html>
<html lang="zh">
    <head>
        <meta charset="utf-8" />
        <title>Custom keyboard shortcuts - Editor.md examples</title>
        <link rel="stylesheet" href="css/style.css" />
        <link rel="stylesheet" href="../css/editormd.css" />
        <link rel="shortcut icon" href="https://pandao.github.io/editor.md/favicon.ico" type="image/x-icon" />
    </head>
    <body>
        <div id="layout">
            <header>
                <h1>Custom keyboard shortcuts</h1>
            </header>
            <div id="test-editormd">
                <textarea style="display:none;">#### Default
 
> If Editor.md code editor is on focus, you can use keyboard shortcuts.
> Editor.md have the default keyboard shortcuts handle. Plaese open the help dialog, can see all default keyboard shortcuts.
 
#### Example
 
```javascript
var testEditor = editormd("test-editormd", {
    width: "90%",
    height: 720,
    path : '../lib/',
    disabledKeyMaps : [
        "Ctrl-B", "F11", "F10"  // disable some default keyboard shortcuts handle
    ],
    onload : function() {
        var keyMap = {
            "Ctrl-S": function(cm) {
                alert("Ctrl+S");
            },
            "Ctrl-A": function(cm) { // default Ctrl-A selectAll
                // custom
                alert("Ctrl+A");
                cm.execCommand("selectAll");
            }
        };
 
        // setting signle key
        var keyMap2 = {
              "Ctrl-T": function(cm) {
                alert("Ctrl+T");
              }
        };
 
        this.addKeyMap(keyMap);
        this.addKeyMap(keyMap2);
        this.removeKeyMap(keyMap2);  // remove signle key
    }
});
```
</textarea>
            </div>
        </div>
        <script src="js/jquery.min.js"></script>
        <script src="../editormd.js"></script>
        <script type="text/javascript">
            var testEditor;
 
            $(function() {   
                var widgets = [];
                
                testEditor = editormd("test-editormd", {
                    width: "90%",
                    height: 720,
                    path : '../lib/',
                    disabledKeyMaps : [
                        "Ctrl-B", "F11", "F10"  // disable some default keyboard shortcuts handle
                    ],
                    onchange : function() {
                                $("#test").remove();
                                var cm = this.cm;
                                var cursor = cm.getCursor();
 
                                //cm.replaceSelection("@");
                                
                                widgets.push(cm.addWidget({line : cursor.line, ch : cursor.ch}, $("<p style='z-index:100000;background:red;color:#fff;padding:5px;' id='test'>fsdfsdfsdf</p>")[0], true));
                                console.log(cm.getCursor(), cm.getLine(cursor.line), cm.getLineTokens(cursor.line));   
                    },
                    onload : function() {
                        var keyMap = {
                            "Ctrl-S": function(cm) {
                                alert("Ctrl+S");
                                //return false;
                            },
                            "Ctrl-A": function(cm) { // default Ctrl-A selectAll
                                // custom
                                alert("Ctrl+A");
                                cm.execCommand("selectAll");
                            },
                            //"Shift-2" : function(cm){
                            //}
                        };
                        
                        this.cm.on("keyup", function(cm){
                            //$("#test").remove();
                        });
                        
                        // setting signle key
                        var keyMap2 = {
                              "Ctrl-T": function(cm) {
                                alert("Ctrl+T");
                              }
                        };
                        
                        this.addKeyMap(keyMap);
                        this.addKeyMap(keyMap2);
                        this.removeKeyMap(keyMap2);  // remove signle key
                    }
                });    
            });
        </script>
    </body>
</html>