今天小編給大家分享一下angular如何使用monaco-editor的相關知識點,內容詳細,邏輯清晰,相信大部分人都還太了解這方面的知識,所以分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后有所收獲,下面我們一起來了解一下吧。
創新互聯公司服務項目包括山亭網站建設、山亭網站制作、山亭網頁制作以及山亭網絡營銷策劃等。多年來,我們專注于互聯網行業,利用自身積累的技術優勢、行業經驗、深度合作伙伴關系等,向廣大中小型企業、政府機構等提供互聯網行業的解決方案,山亭網站推廣取得了明顯的社會效益與經濟效益。目前,我們服務的客戶以成都為中心已經輻射到山亭省份的部分城市,未來相信會繼續擴大服務區域并繼續獲得客戶的支持與信任!
在 angular12 及之前你可以選擇
monaco-editor
ngx-monaco-editor
這是沒有問題的 但是如果你使用了更高版本的 angular 在使用 npm 安裝 ngx-monaco-editor 時 會報錯。
因為原作者似乎已經停止了對這個庫的維護 最終的支持停留在了 angular12 版本
當然 你選擇可以選擇正如提示那樣 用 --force 或者 --legacy-peer-deps 來解決問題
但是為了 消除/避免 隱藏的一些問題 我在原作者的基礎上將框架的 angular 支持提升到了 14 并且會一直更新
當然 你也可以選擇將作者的源代碼移入自己的本地代碼中 這也是完全沒有問題的
base-editor.ts 引入 monaco-editor
config.ts
diff-editor.component.ts
editor.component.ts
editor.module.ts
types.ts
你只需要移動 lib 目錄下的六個文件 然后把它們當成自己項目中的一個 module 去使用就好了
其實所有的 api 都可以在 editor.api.d.ts
這個文件中找到
// 在這個editor下就可以找到所有TS類型
import { editor } from 'monaco-editor';
下面記錄一下常用的
1、設置
// eg
export const READ_EDITOR_OPTIONS: editor.IEditorOptions = {
readOnly: true,
automaticLayout: false,
minimap: {
enabled: false,
},
renderFinalNewline: false,
scrollbar: {
vertical: 'visible',
},
mouseWheelZoom: true,
contextmenu: false,
fontSize: 16,
scrollBeyondLastLine: false,
smoothScrolling: true,
cursorWidth: 0,
renderValidationDecorations: 'off',
colorDecorators: false,
hideCursorInOverviewRuler: true,
overviewRulerLanes: 0,
overviewRulerBorder: false,
};
2、獲取editor實例
<ngx-monaco-editor
[options]="readEditorOptions"
[(ngModel)]="originLogVal"
(onInit)="initViewEditor($event, false)">
</ngx-monaco-editor>
public initViewEditor(editor: editor.ICodeEditor): void {
// 這個editor就是實例
// 下面方法中的editor就是這里的editor
this.editor = editor
}
3、獲取當前光標位置
editor.getPosition()
4、獲取當前鼠標選中的文本
editor.getModel().getValueInRange(editor.getSelection());
5、修改光標位置
editor.setPosition({
column: 1,
lineNumber: 1,
});
6、滾動指定行到可視區中間
editor.revealLineInCenter(1);
7、綁定事件
editor.onMouseDown(event => {
// do something
});
editor.onKeyDown(event => {
// do something
});
8、保存/恢復快照
const snapshot = editor.saveViewState();
editor.restoreViewState(snapshot);
9、阻止某個事件
// eg 組件默認的搜索快捷鍵
function isMac() {
return /macintosh|mac os x/i.test(navigator.userAgent);
}
editor.onKeyDown(event => {
if (
(isMac() && event.browserEvent.key === 'f' && event.metaKey) ||
(!isMac() && event.browserEvent.key === 'f' && event.ctrlKey)
) {
event.preventDefault();
event.stopPropagation();
}
});
以上就是“angular如何使用monaco-editor”這篇文章的所有內容,感謝各位的閱讀!相信大家閱讀完這篇文章都有很大的收獲,小編每天都會為大家更新不同的知識,如果還想學習更多的知識,請關注創新互聯行業資訊頻道。
本文題目:angular如何使用monaco-editor
文章來源:http://m.kartarina.com/article2/pipioc.html
成都網站建設公司_創新互聯,為您提供品牌網站設計、微信小程序、網站維護、網站收錄、云服務器、商城網站
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯