xtext編輯器如何將乳膠符號\rightarrow
翻譯(例如)->
?Xtext,將ascii字符轉換爲數學符號
0
A
回答
1
看一看AUTOEDIT
public class MyDslDefaultAutoEditStrategyProvider extends DefaultAutoEditStrategyProvider {
@Inject
protected Provider<ShortCutEditStrategy> shortCut;
@Override
protected void configureStringLiteral(IEditStrategyAcceptor acceptor) {
acceptor.accept(shortCut.get().configure("->", "\\rightarrow"), IDocument.DEFAULT_CONTENT_TYPE);
}
}
的不錯的功能和不要忘了結合
override Class<? extends AbstractEditStrategyProvider> bindAbstractEditStrategyProvider() {
MyDslDefaultAutoEditStrategyProvider
}
+0
我剛用Unicode代碼字符替換了「\\ rightarrow」:-) – Johan
0
使用JavaScript
很容易。這個簡單的腳本應該有所幫助:
replaceText('->', '\rightarrow');
var replaceText = function (search, replaceWith) {
var area = document.getElementById("area");
var getCount = function (str, search) {
return str.split(search).length - 1;
};
if (area.value.indexOf(search) >= 0) {
var start = area.selectionStart;
var end = area.selectionEnd;
var textBefore = area.value.substr(0, end);
var lengthDiff = (replaceWith.length - search.length) * getCount(textBefore, search);
area.value = area.value.replace(search, replaceWith);
area.selectionStart = start + lengthDiff;
area.selectionEnd = end + lengthDiff;
}
};
此全文可以輕鬆地適應您的使用 - 這裏有一個完整的例子。
<textarea id="area"></textarea>
<script>
function keyDownTextField() {
replaceText('->', '\u2192');
}
var replaceText = function (search, replaceWith) {
var area = document.getElementById("area");
var getCount = function (str, search) {
return str.split(search).length - 1;
};
if (area.value.indexOf(search) >= 0) {
var start = area.selectionStart;
var end = area.selectionEnd;
var textBefore = area.value.substr(0, end);
var lengthDiff = (replaceWith.length - search.length) * getCount(textBefore, search);
area.value = area.value.replace(search, replaceWith);
area.selectionStart = start + lengthDiff;
area.selectionEnd = end + lengthDiff;
}
};
document.addEventListener("keydown", keyDownTextField, false);
</script>
相關問題
- 1. 將字符串轉換爲字符ascii
- 2. 將字符轉換爲ASCII字符
- 3. x86將ASCII字符轉換爲數字
- 4. Bash:將非ASCII字符轉換爲ASCII
- 5. 將數值轉換爲ASCII字符?
- 6. 將字符串轉換爲ascii和ascii爲字符串
- 7. Python將ASCII字符轉換爲字節
- 8. 將字符串轉換爲ASCII和ASCII字符串
- 9. 將ASCII字符轉換爲x11鍵碼
- 10. 將Ascii字符串轉換爲位流
- 11. python將未知字符轉換爲ascii
- 12. 將字符串轉換爲ASCII值
- 13. 將字符轉換爲ASCII的Powershell
- 14. 將字符串轉換爲ASCII
- 15. C++ ::將ASCII值轉換爲字符串
- 16. 在JavaScript中將字符轉換爲ASCII
- 17. 將字符串轉換爲ASCII值python
- 18. 將ASCII轉換爲.NET中的字符
- 19. 將字符串轉換爲ASCII碼
- 20. Rails - 將ascii轉換爲字符
- 21. 將ASCII碼轉換爲字符值
- 22. 將字符串轉換爲ASCII碼
- 23. 將ascii值轉換爲字符
- 24. 將Unicode字符轉換爲擴展ASCII
- 25. 將Unicode字符串轉換爲ASCII
- 26. 將字符串轉換爲ASCII值
- 27. 將ASCII字符轉換爲十六進制轉義字符串
- 28. C將無符號字符轉換爲無符號字符:4
- 29. 將無符號字符轉換爲LPCSTR
- 30. 將JavaScript符號轉換爲字符串?
這是基於Eclipse的Xtext嗎? –
是的,日食Xtext – Johan