2023年10月8日15:40:11
parent
c96026b85c
commit
3853e1dd43
|
|
@ -612,6 +612,10 @@ public class EditListController {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void monaco_js_menu_item(ActionEvent actionEvent) {
|
public void monaco_js_menu_item(ActionEvent actionEvent) {
|
||||||
|
boolean flag = false;
|
||||||
|
if (monacoEdit != null){
|
||||||
|
flag = true;
|
||||||
|
}
|
||||||
|
monacoEdit(flag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -638,4 +638,7 @@ public class HomeController implements Serializable {
|
||||||
listView.getSelectionModel().select(index);
|
listView.getSelectionModel().select(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void monaco_js_menu_item(ActionEvent actionEvent) {
|
||||||
|
js_edit_list(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2,6 +2,9 @@ package com.zhangmeng.tools.editors.monaco;
|
||||||
|
|
||||||
import com.zhangmeng.tools.utils.AlertUtils;
|
import com.zhangmeng.tools.utils.AlertUtils;
|
||||||
import com.zhangmeng.tools.utils.ClipboardUtils;
|
import com.zhangmeng.tools.utils.ClipboardUtils;
|
||||||
|
import javafx.beans.property.SimpleStringProperty;
|
||||||
|
import javafx.beans.value.ObservableValue;
|
||||||
|
import javafx.concurrent.Worker;
|
||||||
import javafx.scene.input.KeyCode;
|
import javafx.scene.input.KeyCode;
|
||||||
import javafx.scene.input.KeyEvent;
|
import javafx.scene.input.KeyEvent;
|
||||||
import javafx.scene.layout.AnchorPane;
|
import javafx.scene.layout.AnchorPane;
|
||||||
|
|
@ -16,10 +19,91 @@ import java.io.IOException;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import netscape.javascript.JSObject;
|
import netscape.javascript.JSObject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* editor.action.addCommentLine:添加行注释(Toggle Line Comment)
|
||||||
|
* editor.action.addCursorsToBottom:在文件尾部添加光标(Add Cursors To Bottom)
|
||||||
|
* editor.action.addCursorsToTop:在文件开头添加光标(Add Cursors To Top)
|
||||||
|
* editor.action.addSelectionToNextFindMatch:选取当前匹配后的下一个匹配项(Add Selection To Next Find Match)
|
||||||
|
* editor.action.addSelectionToPreviousFindMatch:选取当前匹配前的上一个匹配项(Add Selection To Previous Find Match)
|
||||||
|
* editor.action.centerLineInViewport:将当前行垂直居中(Center Line In Viewport)
|
||||||
|
* editor.action.clipboardCopyAction:复制当前选中内容到剪切板(Copy)
|
||||||
|
* editor.action.clipboardCutAction:剪切当前选中内容到剪切板(Cut)
|
||||||
|
* editor.action.clipboardPasteAction:从剪切板中粘贴内容(Paste)
|
||||||
|
* editor.action.commentLine:对选中文本添加或取消行注释(Toggle Line Comment)
|
||||||
|
* editor.action.copyLinesDownAction:复制当前行并粘贴到下一行(Copy Lines Down)
|
||||||
|
* editor.action.copyLinesUpAction:复制当前行并粘贴到上一行(Copy Lines Up)
|
||||||
|
* editor.action.createCursorUndo:撤销所有光标修改(Undo Cursor)
|
||||||
|
* editor.action.cursorColumnSelectDown:向下纵向区域选择行(Cursor Column Select Down)
|
||||||
|
* editor.action.cursorColumnSelectLeft:向左纵向区域选择该行字符(Cursor Column Select Left)
|
||||||
|
* editor.action.cursorColumnSelectPageDown:向下以页面为单位进行纵向区域选择(Cursor Column Select Page Down)
|
||||||
|
* editor.action.cursorColumnSelectPageUp:向上以页面为单位进行纵向区域选择(Cursor Column Select Page Up)
|
||||||
|
* editor.action.cursorColumnSelectRight:向右纵向区域选择该行字符(Cursor Column Select Right)
|
||||||
|
* editor.action.cursorColumnSelectUp:向上纵向区域选择行(Cursor Column Select Up)
|
||||||
|
* editor.action.cursorDown:将光标向下移动(Cursor Down)
|
||||||
|
* editor.action.cursorEnd:将光标定位到行末尾(Cursor End)
|
||||||
|
* editor.action.cursorHalfPageDown:向下移动半个页面距离(Cursor Half Page Down)
|
||||||
|
* editor.action.cursorHalfPageUp:向上移动半个页面距离(Cursor Half Page Up)
|
||||||
|
* editor.action.cursorHome:将光标定位到行首(Cursor Home)
|
||||||
|
* editor.action.cursorLeft:将光标向左移动(Cursor Left)
|
||||||
|
* editor.action.cursorPageDown:向下翻页(Cursor Page Down)
|
||||||
|
* editor.action.cursorPageUp:向上翻页(Cursor Page Up)
|
||||||
|
* editor.action.cursorRight:将光标向右移动(Cursor Right)
|
||||||
|
* editor.action.cursorTop:将光标定位到文件开头(Cursor Top)
|
||||||
|
* editor.action.cursorUp:将光标向上移动(Cursor Up)
|
||||||
|
* editor.action.deleteLines:删除当前行或选中的多行(Delete Lines)
|
||||||
|
* editor.action.deleteAllLeft:删除光标到行首的所有内容(Delete All Left)
|
||||||
|
* editor.action.deleteAllRight:删除光标到行尾的所有内容(Delete All Right)
|
||||||
|
* editor.action.deleteLeft:删除光标前的字符(Delete Left)
|
||||||
|
* editor.action.deleteRight:删除光标后的字符(Delete Right)
|
||||||
|
* editor.action.duplicateSelection:复制并插入一份当前选中内容(Duplicate Selection)
|
||||||
|
* editor.action.editor.action.insertSnippet:插入代码片段(Insert Snippet)
|
||||||
|
* editor.action.filterActions:将行为过滤器或快捷键过滤器应用于列表(Filter Actions)
|
||||||
|
* editor.action.goToDeclaration:跳转到变量声明处(Go to Declaration)
|
||||||
|
* editor.action.goToImplementation:跳转到变量实现处(Go to Implementation)
|
||||||
|
* editor.action.goToTypeDefinition:查找类型定义(Go to Type Definition)
|
||||||
|
* editor.action.insertCursorAbove:插入一个向上的光标(Insert Cursor Above)
|
||||||
|
* editor.action.insertCursorAtEndOfEachLineSelected:插入在每行末尾的光标(Insert Cursor at End of Each Line Selected)
|
||||||
|
* editor.action.insertCursorBelow:插入一个向下的光标(Insert Cursor Below)
|
||||||
|
* editor.action.insertLineAfter:在当前行下面插入一行(Insert Line After)
|
||||||
|
* editor.action.insertLineBefore:在当前行上面插入一行(Insert Line Before)
|
||||||
|
* editor.action.indentLines:将选中行缩进(Indent Lines)
|
||||||
|
* editor.action.indentUsingSpaces:使用空格进行缩进(Indent Using Spaces)
|
||||||
|
* editor.action.intersectSelections:保留所有光标的交集,取消其余光标(Intersect Selections)
|
||||||
|
* editor.action.moveLinesDownAction:将选中的行向下移动一行(Move Lines Down)
|
||||||
|
* editor.action.moveLinesUpAction:将选中的行向上移动一行(Move Lines Up)
|
||||||
|
* editor.action.moveSelectionToNextFindMatch:将光标移到下一个匹配项处,并取消选择(Move Selection to Next Find Match)
|
||||||
|
* editor.action.moveSelectionToPreviousFindMatch:将光标移到上一个匹配项处,并取消选择(Move Selection to Previous Find Match)
|
||||||
|
* editor.action.moveToCenter:将光标定位到屏幕中央(Move To Center)
|
||||||
|
* editor.action.navigateToNextError:跳转到下一个错误(Go to Next Error)
|
||||||
|
* editor.action.navigateToPreviousError:跳转到上一个错误(Go to Previous Error)
|
||||||
|
* editor.action.newLineAbove:在当前行上方新建一行(New Line Above)
|
||||||
|
* editor.action.newLineBelow:在当前行下方新建一行(New Line Below)
|
||||||
|
* editor.action.nextMatchFindAction:查找下一个匹配项(Next Match Find)
|
||||||
|
* editor.action.outdentLines:将选中行的缩进减少(Outdent Lines)
|
||||||
|
* editor.action.outdentUsingSpaces:使用空格减少缩进(Outdent Using Spaces)
|
||||||
|
* editor.action.pasteSelection:粘贴文本并替换当前选中内容(Paste Selection)
|
||||||
|
* editor.action.quickFix:快速修复错误(Quick Fix)
|
||||||
|
* editor.action.quickOutline:打开当前文件的大纲视图(Quick Outline)
|
||||||
|
* editor.action.redo:重做最近一次取消操作(Redo)
|
||||||
|
* editor.action.referenceSearch.trigger:查找该变量的所有引用(Find All References)
|
||||||
|
* editor.action.removeCommentLine:移除行注释(Toggle Line Comment)
|
||||||
|
* editor.action.replaceAll:在全局范围内查找并替换所有匹配项;(Replace All);通常使用 Command+Shift+H 快捷键
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
public class MonacoWebView extends AnchorPane {
|
public class MonacoWebView extends AnchorPane {
|
||||||
|
|
||||||
|
public SimpleStringProperty text_code = new SimpleStringProperty("");
|
||||||
|
|
||||||
|
public void setText(String text){
|
||||||
|
log.info("text:" + text);
|
||||||
|
text_code.setValue(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
private JSObject window;
|
||||||
|
|
||||||
public MonacoWebView() {
|
public MonacoWebView() {
|
||||||
init();
|
init();
|
||||||
|
|
@ -50,6 +134,16 @@ public class MonacoWebView extends AnchorPane {
|
||||||
WebEngine engine = view.getEngine();
|
WebEngine engine = view.getEngine();
|
||||||
|
|
||||||
String url = this.getClass().getResource("/static/editors/index2.html").toExternalForm();
|
String url = this.getClass().getResource("/static/editors/index2.html").toExternalForm();
|
||||||
|
|
||||||
|
engine.getLoadWorker().stateProperty().addListener(
|
||||||
|
(ObservableValue<? extends Worker.State> ov, Worker.State oldState, Worker.State newState) -> {
|
||||||
|
if (newState == Worker.State.SUCCEEDED) {
|
||||||
|
window = (JSObject) engine.executeScript("window");
|
||||||
|
window.setMember("text_code",text_code);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
engine.load(url);
|
engine.load(url);
|
||||||
AnchorPane.setTopAnchor(view, 0.0);
|
AnchorPane.setTopAnchor(view, 0.0);
|
||||||
AnchorPane.setBottomAnchor(view, 0.0);
|
AnchorPane.setBottomAnchor(view, 0.0);
|
||||||
|
|
@ -58,7 +152,7 @@ public class MonacoWebView extends AnchorPane {
|
||||||
getChildren().add(view);
|
getChildren().add(view);
|
||||||
|
|
||||||
view.addEventFilter(KeyEvent.KEY_PRESSED, event -> {
|
view.addEventFilter(KeyEvent.KEY_PRESSED, event -> {
|
||||||
|
log.info("event.getCode:" + event.getCode());
|
||||||
if (event.isControlDown() && event.getCode() == KeyCode.C) {
|
if (event.isControlDown() && event.getCode() == KeyCode.C) {
|
||||||
event.consume();
|
event.consume();
|
||||||
JSObject editor = (JSObject) engine.executeScript("window");
|
JSObject editor = (JSObject) engine.executeScript("window");
|
||||||
|
|
@ -82,6 +176,11 @@ public class MonacoWebView extends AnchorPane {
|
||||||
AlertUtils.alert_warning("保存成功!");
|
AlertUtils.alert_warning("保存成功!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (event.isControlDown() && event.getCode() == KeyCode.CONTROL) {//注释
|
||||||
|
event.consume();
|
||||||
|
window.call("commentLine");
|
||||||
|
}
|
||||||
|
|
||||||
if (event.isControlDown() && event.getCode() == KeyCode.O) {
|
if (event.isControlDown() && event.getCode() == KeyCode.O) {
|
||||||
event.consume();
|
event.consume();
|
||||||
//打开文件
|
//打开文件
|
||||||
|
|
|
||||||
|
|
@ -362,7 +362,7 @@ public class ResourcesUtils {
|
||||||
public enum EditorList {
|
public enum EditorList {
|
||||||
|
|
||||||
Ace_JS("ace.js 编辑器", 0),
|
Ace_JS("ace.js 编辑器", 0),
|
||||||
Monaco_JS("ace.js 编辑器", 1),
|
Monaco_JS("monaco.js 编辑器", 1),
|
||||||
;
|
;
|
||||||
|
|
||||||
EditorList(String title, int index) {
|
EditorList(String title, int index) {
|
||||||
|
|
|
||||||
|
|
@ -106,6 +106,7 @@
|
||||||
<Menu mnemonicParsing="false" text="编辑器工具">
|
<Menu mnemonicParsing="false" text="编辑器工具">
|
||||||
<items>
|
<items>
|
||||||
<MenuItem mnemonicParsing="false" text="ace.js 编辑器" onAction="#ace_js_menu_item"/>
|
<MenuItem mnemonicParsing="false" text="ace.js 编辑器" onAction="#ace_js_menu_item"/>
|
||||||
|
<MenuItem mnemonicParsing="false" text="monaco.js 编辑器" onAction="#monaco_js_menu_item"/>
|
||||||
</items>
|
</items>
|
||||||
</Menu>
|
</Menu>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -64,9 +64,33 @@
|
||||||
},
|
},
|
||||||
fontSize: 18,
|
fontSize: 18,
|
||||||
lineNumbers: true,
|
lineNumbers: true,
|
||||||
|
scrollbar: {
|
||||||
|
// Subtle shadows to the left & top. Defaults to true.
|
||||||
|
useShadows: true,
|
||||||
|
|
||||||
|
// Render vertical arrows. Defaults to false.
|
||||||
|
verticalHasArrows: true,
|
||||||
|
// Render horizontal arrows. Defaults to false.
|
||||||
|
horizontalHasArrows: true,
|
||||||
|
|
||||||
|
// Render vertical scrollbar.
|
||||||
|
// Accepted values: 'auto', 'visible', 'hidden'.
|
||||||
|
// Defaults to 'auto'
|
||||||
|
vertical: 'auto',
|
||||||
|
// Render horizontal scrollbar.
|
||||||
|
// Accepted values: 'auto', 'visible', 'hidden'.
|
||||||
|
// Defaults to 'auto'
|
||||||
|
horizontal: 'auto',
|
||||||
|
verticalScrollbarSize: 10,
|
||||||
|
horizontalScrollbarSize: 10,
|
||||||
|
arrowSize: 30,
|
||||||
|
alwaysConsumeMouseWheel: false
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
editor.onDidChangeCursorPosition((e) => {
|
editor.onDidChangeCursorPosition((e) => {
|
||||||
edit_content = editor.getValue();
|
edit_content = editor.getValue();
|
||||||
|
window.text_code.setValue(edit_content)
|
||||||
});
|
});
|
||||||
code_edit = editor;
|
code_edit = editor;
|
||||||
return editor;
|
return editor;
|
||||||
|
|
@ -86,7 +110,12 @@
|
||||||
|
|
||||||
//获取值
|
//获取值
|
||||||
function getValue() {
|
function getValue() {
|
||||||
alert(edit_content)
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//添加或取消注释
|
||||||
|
function commentLine(){
|
||||||
|
getActionToTrigger("editor.action.commentLine")
|
||||||
}
|
}
|
||||||
|
|
||||||
function setThem() {
|
function setThem() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue