Skip to content

Commit fc7f8b1

Browse files
committedJul 25, 2018
make it work
1 parent c191b9d commit fc7f8b1

File tree

10 files changed

+308
-187
lines changed

10 files changed

+308
-187
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ jam/
2323
.git-ref
2424
npm-debug.log
2525
deps/
26+
dist

‎demo/kitchen-sink/demo.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -424,11 +424,17 @@ optionsPanel.add({
424424
events.forEach(function(name) {
425425
text.addEventListener(name, addToLog, true);
426426
});
427+
function onMousedown(ev) {
428+
if (ev.domEvent.target == text)
429+
ev.$pos = editor.getCursorPosition();
430+
}
427431
text.detach = function() {
428432
events.forEach(function(name) {
429433
text.removeEventListener(name, addToLog, true);
430434
});
435+
editor.off("mousedown", onMousedown);
431436
};
437+
editor.on("mousedown", onMousedown);
432438

433439
var log = sp.$editors[1];
434440
if (!this.session)
@@ -540,7 +546,6 @@ optionsPanelContainer.insertBefore(
540546
require("ace/ext/language_tools");
541547
env.editor.setOptions({
542548
enableBasicAutocompletion: true,
543-
enableLiveAutocompletion: false,
544549
enableSnippets: true
545550
});
546551

‎demo/kitchen-sink/styles.css

+3-1
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,12 @@ body {
5757
}*/
5858
.text-input-debug {
5959
height: 100px!important;
60-
position: absolute;
60+
position: absolute!important;
61+
transform: none!important;
6162
top: 0px!important;
6263
left: 7px!important;
6364
width: 260px!important;
6465
z-index: 1000!important;
6566
opacity: 1!important;
67+
font-size: 1em!important;
6668
}

‎lib/ace/css/editor.css

+38-29
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,31 @@
1+
/*
2+
styles = []
3+
for (var i = 1; i < 16; i++) {
4+
styles.push(".ace_br" + i + "{" + (
5+
["top-left", "top-right", "bottom-right", "bottom-left"]
6+
).map(function(x, j) {
7+
return i & (1<<j) ? "border-" + x + "-radius: 3px;" : ""
8+
}).filter(Boolean).join(" ") + "}")
9+
}
10+
styles.join("\n")
11+
*/
12+
.ace_br1 {border-top-left-radius : 3px;}
13+
.ace_br2 {border-top-right-radius : 3px;}
14+
.ace_br3 {border-top-left-radius : 3px; border-top-right-radius: 3px;}
15+
.ace_br4 {border-bottom-right-radius: 3px;}
16+
.ace_br5 {border-top-left-radius : 3px; border-bottom-right-radius: 3px;}
17+
.ace_br6 {border-top-right-radius : 3px; border-bottom-right-radius: 3px;}
18+
.ace_br7 {border-top-left-radius : 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px;}
19+
.ace_br8 {border-bottom-left-radius : 3px;}
20+
.ace_br9 {border-top-left-radius : 3px; border-bottom-left-radius: 3px;}
21+
.ace_br10{border-top-right-radius : 3px; border-bottom-left-radius: 3px;}
22+
.ace_br11{border-top-left-radius : 3px; border-top-right-radius: 3px; border-bottom-left-radius: 3px;}
23+
.ace_br12{border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}
24+
.ace_br13{border-top-left-radius : 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}
25+
.ace_br14{border-top-right-radius : 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}
26+
.ace_br15{border-top-left-radius : 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}
27+
28+
129
.ace_editor {
230
position: relative;
331
overflow: hidden;
@@ -148,7 +176,7 @@
148176
font: inherit;
149177
padding: 0 1px;
150178
margin: 0 -1px;
151-
text-indent: -1em;
179+
contain: strict;
152180
-ms-user-select: text;
153181
-moz-user-select: text;
154182
-webkit-user-select: text;
@@ -157,12 +185,19 @@
157185
white-space: pre!important;
158186
}
159187
.ace_text-input.ace_composition {
160-
background: inherit;
188+
background: transparent;
161189
color: inherit;
162190
z-index: 1000;
163191
opacity: 1;
164-
text-indent: 0;
165192
}
193+
.ace_composition_placeholder { color: transparent }
194+
.ace_composition_marker {
195+
border-bottom: 1px solid;
196+
position: absolute;
197+
border-radius: 0;
198+
margin-top: 1px;
199+
}
200+
166201
[ace_nocontext=true] {
167202
transform: none!important;
168203
filter: none!important;
@@ -494,32 +529,6 @@
494529
z-index: 8;
495530
}
496531

497-
/*
498-
styles = []
499-
for (var i = 1; i < 16; i++) {
500-
styles.push(".ace_br" + i + "{" + (
501-
["top-left", "top-right", "bottom-right", "bottom-left"]
502-
).map(function(x, j) {
503-
return i & (1<<j) ? "border-" + x + "-radius: 3px;" : ""
504-
}).filter(Boolean).join(" ") + "}")
505-
}
506-
styles.join("\n")
507-
*/
508-
.ace_br1 {border-top-left-radius : 3px;}
509-
.ace_br2 {border-top-right-radius : 3px;}
510-
.ace_br3 {border-top-left-radius : 3px; border-top-right-radius: 3px;}
511-
.ace_br4 {border-bottom-right-radius: 3px;}
512-
.ace_br5 {border-top-left-radius : 3px; border-bottom-right-radius: 3px;}
513-
.ace_br6 {border-top-right-radius : 3px; border-bottom-right-radius: 3px;}
514-
.ace_br7 {border-top-left-radius : 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px;}
515-
.ace_br8 {border-bottom-left-radius : 3px;}
516-
.ace_br9 {border-top-left-radius : 3px; border-bottom-left-radius: 3px;}
517-
.ace_br10{border-top-right-radius : 3px; border-bottom-left-radius: 3px;}
518-
.ace_br11{border-top-left-radius : 3px; border-top-right-radius: 3px; border-bottom-left-radius: 3px;}
519-
.ace_br12{border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}
520-
.ace_br13{border-top-left-radius : 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}
521-
.ace_br14{border-top-right-radius : 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}
522-
.ace_br15{border-top-left-radius : 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}
523532

524533
.ace_text-input-ios {
525534
position: absolute !important;

‎lib/ace/editor.js

+39-10
Original file line numberDiff line numberDiff line change
@@ -145,21 +145,21 @@ Editor.$uid = 0;
145145

146146
this.curOp = null;
147147
this.prevOp = {};
148-
this.startOperation = function(commadEvent) {
148+
this.startOperation = function(commandEvent) {
149149
if (this.curOp) {
150-
if (!commadEvent || this.curOp.command)
150+
if (!commandEvent || this.curOp.command)
151151
return;
152152
this.prevOp = this.curOp;
153153
}
154-
if (!commadEvent) {
154+
if (!commandEvent) {
155155
this.previousCommand = null;
156-
commadEvent = {};
156+
commandEvent = {};
157157
}
158158

159159
this.$opResetTimer.schedule();
160160
this.curOp = this.session.curOp = {
161-
command: commadEvent.command || {},
162-
args: commadEvent.args,
161+
command: commandEvent.command || {},
162+
args: commandEvent.args,
163163
scrollTop: this.renderer.scrollTop
164164
};
165165
this.curOp.selectionBefore = this.selection.toJSON();
@@ -1062,8 +1062,36 @@ Editor.$uid = 0;
10621062
mode.autoOutdent(lineState, session, cursor.row);
10631063
};
10641064

1065-
this.onTextInput = function(text) {
1066-
this.keyBinding.onTextInput(text);
1065+
this.onTextInput = function(text, composition) {
1066+
if (!composition)
1067+
return this.keyBinding.onTextInput(text);
1068+
1069+
this.startOperation({command: { name: "insertstring" }});
1070+
var applyComposition = this.applyComposition.bind(this, text, composition);
1071+
if (this.selection.rangeCount)
1072+
this.forEachSelection(applyComposition);
1073+
else
1074+
applyComposition();
1075+
this.endOperation();
1076+
};
1077+
1078+
this.applyComposition = function(text, composition) {
1079+
if (composition.extendLeft || composition.extendRight) {
1080+
var r = this.selection.getRange();
1081+
r.start.column -= composition.extendLeft;
1082+
r.end.column += composition.extendRight;
1083+
this.selection.setRange(r);
1084+
if (!text && !r.isEmpty())
1085+
this.remove();
1086+
}
1087+
if (text || !this.selection.isEmpty())
1088+
this.insert(text, true);
1089+
if (composition.restoreStart || composition.restoreEnd) {
1090+
var r = this.selection.getRange();
1091+
r.start.column -= composition.restoreStart;
1092+
r.end.column -= composition.restoreEnd;
1093+
this.selection.setRange(r);
1094+
}
10671095
};
10681096

10691097
this.onCommandKey = function(e, hashId, keyCode) {
@@ -1894,8 +1922,8 @@ Editor.$uid = 0;
18941922
};
18951923
};
18961924

1897-
this.onCompositionStart = function(text) {
1898-
this.renderer.showComposition(this.getCursorPosition());
1925+
this.onCompositionStart = function(compositionState) {
1926+
this.renderer.showComposition(compositionState);
18991927
};
19001928

19011929
this.onCompositionUpdate = function(text) {
@@ -2812,6 +2840,7 @@ config.defineOptions(Editor.prototype, "editor", {
28122840
theme: "renderer",
28132841
hasCssTransforms: "renderer",
28142842
maxPixelHeight: "renderer",
2843+
useTextareaForIME: "renderer",
28152844

28162845
scrollSpeed: "$mouseHandler",
28172846
dragDelay: "$mouseHandler",

‎lib/ace/ext/options.js

+3
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ var optionGroups = {
153153
"Fade Fold Widgets": {
154154
path: "fadeFoldWidgets"
155155
},
156+
"Use textarea for IME": {
157+
path: "useTextareaForIME"
158+
},
156159
"Merge Undo Deltas": {
157160
path: "mergeUndoDeltas",
158161
items: [

0 commit comments

Comments
 (0)
Please sign in to comment.