差分
このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン | ||
javascript:ace [2019/07/31 16:41] – ともやん | javascript:ace [2020/06/15 19:46] (現在) – ↷ 移動操作に合わせてリンクを書き換えました。 非ログインユーザー | ||
---|---|---|---|
行 1: | 行 1: | ||
+ | < | ||
+ | <script src='/ | ||
+ | <script src="/ | ||
+ | <!--[if lt IE 9]> | ||
+ | <script src="/ | ||
+ | < | ||
+ | <script src="/ | ||
+ | <script src="/ | ||
+ | <script src="/ | ||
+ | <script src="/ | ||
+ | <script src="/ | ||
+ | <script src="/ | ||
+ | <script src="/ | ||
+ | <script src="/ | ||
+ | < | ||
+ | jQuery(function($) { | ||
+ | const editor = ace.edit(" | ||
+ | editor.setTheme(" | ||
+ | editor.session.setMode(" | ||
+ | editor.setValue(editor.getValue().trim(), | ||
+ | const lines = editor.getSession().getDocument().getLength(); | ||
+ | editor.setOptions({maxLines: | ||
+ | }); | ||
+ | </ | ||
+ | < | ||
+ | #ace_editor { | ||
+ | margin-bottom: | ||
+ | } | ||
+ | </ | ||
+ | </ | ||
====== Ace - The High Performance Code Editor for the Web ====== | ====== Ace - The High Performance Code Editor for the Web ====== | ||
Ace はJavaScriptで記述された、Webシステムに組み込み可能なコードエディタです。\\ | Ace はJavaScriptで記述された、Webシステムに組み込み可能なコードエディタです。\\ | ||
行 4: | 行 34: | ||
本家: [[https:// | 本家: [[https:// | ||
ソースコード: | ソースコード: | ||
+ | |||
+ | ===== エディタデモ ===== | ||
+ | <WRAP prewrap 100% # | ||
+ | %%/** | ||
+ | * In fact, you're looking at ACE right now. Go ahead and play with it! | ||
+ | * | ||
+ | * We are currently showing off the JavaScript mode. ACE has support for 45 | ||
+ | * language modes and 24 color themes! | ||
+ | */ | ||
+ | |||
+ | function add(x, y) { | ||
+ | var resultString = " | ||
+ | var result = x + y; | ||
+ | return resultString + result; | ||
+ | } | ||
+ | |||
+ | var addResult = add(3, 2); | ||
+ | console.log(addResult); | ||
+ | </ | ||
+ | <code html> | ||
+ | <script src='/ | ||
+ | <script src="/ | ||
+ | <!--[if lt IE 9]> | ||
+ | <script src="/ | ||
+ | < | ||
+ | <script src="/ | ||
+ | <script src="/ | ||
+ | <script src="/ | ||
+ | <script src="/ | ||
+ | <script src="/ | ||
+ | <script src="/ | ||
+ | <script src="/ | ||
+ | <script src="/ | ||
+ | < | ||
+ | jQuery(function($) { | ||
+ | const editor = ace.edit(" | ||
+ | editor.setTheme(" | ||
+ | editor.session.setMode(" | ||
+ | const lines = editors[i].getSession().getDocument().getLength(); | ||
+ | editor.setOptions({maxLines: | ||
+ | }); | ||
+ | </ | ||
+ | </ | ||
===== インストール ===== | ===== インストール ===== | ||
行 14: | 行 87: | ||
==== ソースコードからのインストール ==== | ==== ソースコードからのインストール ==== | ||
- | Ace をソースからビルドするには [[javascript: | + | Ace をソースからビルドするには [[javascript: |
\\ | \\ | ||
ソースを取得する。 | ソースを取得する。 | ||
行 41: | 行 114: | ||
$ make build | $ make build | ||
</ | </ | ||
+ | |||
+ | ===== //#region [リージョンの説明] 〜 //# | ||
+ | 実際のデモは以下にある。\\ | ||
+ | [[javascript: | ||
+ | <code javascript> | ||
+ | //#region [Ace Editor fold all region] | ||
+ | isCommentFold = (line) => { | ||
+ | var isAFold = false; | ||
+ | if (/ | ||
+ | if (/ | ||
+ | return isAFold; | ||
+ | } | ||
+ | ace.EditSession.prototype.foldAllRegion = function(startRow, | ||
+ | if (depth == undefined) | ||
+ | depth = 100000; // JSON.stringify doesn' | ||
+ | var foldWidgets = this.foldWidgets; | ||
+ | if (!foldWidgets) | ||
+ | return; // mode doesn' | ||
+ | endRow = endRow || this.getLength(); | ||
+ | startRow = startRow || 0; | ||
+ | for (var row = startRow; row < endRow; row++) { | ||
+ | if (foldWidgets[row] == null) | ||
+ | foldWidgets[row] = this.getFoldWidget(row); | ||
+ | if (foldWidgets[row] != " | ||
+ | continue; | ||
+ | if (!isCommentFold(this.getLine(row))) continue | ||
+ | var range = this.getFoldWidgetRange(row); | ||
+ | // sometimes range can be incompatible with existing fold | ||
+ | // TODO change addFold to return null istead of throwing | ||
+ | if (range && range.isMultiLine() | ||
+ | && range.end.row <= endRow | ||
+ | && range.start.row >= startRow) { | ||
+ | row = range.end.row; | ||
+ | try { | ||
+ | // addFold can change the range | ||
+ | var fold = this.addFold(" | ||
+ | if (fold) | ||
+ | fold.collapseChildren = depth; | ||
+ | } catch(ex) {} | ||
+ | } | ||
+ | } | ||
+ | }; | ||
+ | //# | ||
+ | | ||
+ | jQuery(function($) { | ||
+ | const editor = ace.edit(" | ||
+ | editor.setTheme(" | ||
+ | editor.session.setMode(" | ||
+ | const lines = editors[i].getSession().getDocument().getLength(); | ||
+ | editor.setOptions({maxLines: | ||
+ | | ||
+ | // #region をデフォルトで折り畳む | ||
+ | editor.session.foldAllRegion(); | ||
+ | }); | ||
+ | </ | ||
+ |