2023年10月8日15:40:11

master
zhangmeng 2023-10-08 15:40:23 +08:00
parent c96026b85c
commit 3853e1dd43
6 changed files with 140 additions and 4 deletions

View File

@ -612,6 +612,10 @@ public class EditListController {
}
public void monaco_js_menu_item(ActionEvent actionEvent) {
boolean flag = false;
if (monacoEdit != null){
flag = true;
}
monacoEdit(flag);
}
}

View File

@ -638,4 +638,7 @@ public class HomeController implements Serializable {
listView.getSelectionModel().select(index);
}
public void monaco_js_menu_item(ActionEvent actionEvent) {
js_edit_list(1);
}
}

View File

@ -2,6 +2,9 @@ package com.zhangmeng.tools.editors.monaco;
import com.zhangmeng.tools.utils.AlertUtils;
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.KeyEvent;
import javafx.scene.layout.AnchorPane;
@ -16,10 +19,91 @@ import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import lombok.extern.slf4j.Slf4j;
import netscape.javascript.JSObject;
/**
* editor.action.addCommentLineToggle Line Comment
* editor.action.addCursorsToBottomAdd Cursors To Bottom
* editor.action.addCursorsToTopAdd Cursors To Top
* editor.action.addSelectionToNextFindMatchAdd Selection To Next Find Match
* editor.action.addSelectionToPreviousFindMatchAdd Selection To Previous Find Match
* editor.action.centerLineInViewportCenter Line In Viewport
* editor.action.clipboardCopyActionCopy
* editor.action.clipboardCutActionCut
* editor.action.clipboardPasteActionPaste
* editor.action.commentLineToggle Line Comment
* editor.action.copyLinesDownActionCopy Lines Down
* editor.action.copyLinesUpActionCopy Lines Up
* editor.action.createCursorUndoUndo Cursor
* editor.action.cursorColumnSelectDownCursor Column Select Down
* editor.action.cursorColumnSelectLeftCursor Column Select Left
* editor.action.cursorColumnSelectPageDownCursor Column Select Page Down
* editor.action.cursorColumnSelectPageUpCursor Column Select Page Up
* editor.action.cursorColumnSelectRightCursor Column Select Right
* editor.action.cursorColumnSelectUpCursor Column Select Up
* editor.action.cursorDownCursor Down
* editor.action.cursorEndCursor End
* editor.action.cursorHalfPageDownCursor Half Page Down
* editor.action.cursorHalfPageUpCursor Half Page Up
* editor.action.cursorHomeCursor Home
* editor.action.cursorLeftCursor Left
* editor.action.cursorPageDownCursor Page Down
* editor.action.cursorPageUpCursor Page Up
* editor.action.cursorRightCursor Right
* editor.action.cursorTopCursor Top
* editor.action.cursorUpCursor Up
* editor.action.deleteLinesDelete Lines
* editor.action.deleteAllLeftDelete All Left
* editor.action.deleteAllRightDelete All Right
* editor.action.deleteLeftDelete Left
* editor.action.deleteRightDelete Right
* editor.action.duplicateSelectionDuplicate Selection
* editor.action.editor.action.insertSnippetInsert Snippet
* editor.action.filterActionsFilter Actions
* editor.action.goToDeclarationGo to Declaration
* editor.action.goToImplementationGo to Implementation
* editor.action.goToTypeDefinitionGo to Type Definition
* editor.action.insertCursorAboveInsert Cursor Above
* editor.action.insertCursorAtEndOfEachLineSelected(Insert Cursor at End of Each Line Selected)
* editor.action.insertCursorBelowInsert Cursor Below
* editor.action.insertLineAfterInsert Line After
* editor.action.insertLineBeforeInsert Line Before
* editor.action.indentLinesIndent Lines
* editor.action.indentUsingSpaces使Indent Using Spaces
* editor.action.intersectSelectionsIntersect Selections
* editor.action.moveLinesDownActionMove Lines Down
* editor.action.moveLinesUpActionMove Lines Up
* editor.action.moveSelectionToNextFindMatchMove Selection to Next Find Match
* editor.action.moveSelectionToPreviousFindMatchMove Selection to Previous Find Match
* editor.action.moveToCenterMove To Center
* editor.action.navigateToNextErrorGo to Next Error
* editor.action.navigateToPreviousErrorGo to Previous Error
* editor.action.newLineAboveNew Line Above
* editor.action.newLineBelowNew Line Below
* editor.action.nextMatchFindActionNext Match Find
* editor.action.outdentLinesOutdent Lines
* editor.action.outdentUsingSpaces使Outdent Using Spaces
* editor.action.pasteSelectionPaste Selection
* editor.action.quickFixQuick Fix
* editor.action.quickOutlineQuick Outline
* editor.action.redoRedo
* editor.action.referenceSearch.triggerFind All References
* editor.action.removeCommentLineToggle Line Comment
* editor.action.replaceAllReplace All使 Command+Shift+H
*/
@Slf4j
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() {
init();
@ -50,6 +134,16 @@ public class MonacoWebView extends AnchorPane {
WebEngine engine = view.getEngine();
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);
AnchorPane.setTopAnchor(view, 0.0);
AnchorPane.setBottomAnchor(view, 0.0);
@ -58,7 +152,7 @@ public class MonacoWebView extends AnchorPane {
getChildren().add(view);
view.addEventFilter(KeyEvent.KEY_PRESSED, event -> {
log.info("event.getCode:" + event.getCode());
if (event.isControlDown() && event.getCode() == KeyCode.C) {
event.consume();
JSObject editor = (JSObject) engine.executeScript("window");
@ -82,6 +176,11 @@ public class MonacoWebView extends AnchorPane {
AlertUtils.alert_warning("保存成功!");
}
if (event.isControlDown() && event.getCode() == KeyCode.CONTROL) {//注释
event.consume();
window.call("commentLine");
}
if (event.isControlDown() && event.getCode() == KeyCode.O) {
event.consume();
//打开文件

View File

@ -362,7 +362,7 @@ public class ResourcesUtils {
public enum EditorList {
Ace_JS("ace.js 编辑器", 0),
Monaco_JS("ace.js 编辑器", 1),
Monaco_JS("monaco.js 编辑器", 1),
;
EditorList(String title, int index) {

View File

@ -106,6 +106,7 @@
<Menu mnemonicParsing="false" text="编辑器工具">
<items>
<MenuItem mnemonicParsing="false" text="ace.js 编辑器" onAction="#ace_js_menu_item"/>
<MenuItem mnemonicParsing="false" text="monaco.js 编辑器" onAction="#monaco_js_menu_item"/>
</items>
</Menu>

View File

@ -64,9 +64,33 @@
},
fontSize: 18,
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) => {
edit_content = editor.getValue();
window.text_code.setValue(edit_content)
});
code_edit = editor;
return editor;
@ -86,7 +110,12 @@
//获取值
function getValue() {
alert(edit_content)
}
//添加或取消注释
function commentLine(){
getActionToTrigger("editor.action.commentLine")
}
function setThem() {