mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
search dialog WIP from custom widget from antoniotejada
This commit is contained in:
parent
83afb89a16
commit
87f436c6ea
@ -1671,7 +1671,7 @@
|
||||
|
||||
|
||||
|
||||
<h4 class="name" id="addTextToActiveTabEditor"><span class="type-signature"></span>addTextToActiveTabEditor<span class="signature">(text)</span><span class="type-signature"></span></h4>
|
||||
<h4 class="name" id="addTextToActiveContextEditor"><span class="type-signature"></span>addTextToActiveContextEditor<span class="signature">(text)</span><span class="type-signature"></span></h4>
|
||||
|
||||
|
||||
|
||||
@ -1772,7 +1772,146 @@
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line327">line 327</a>
|
||||
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line340">line 340</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h4 class="name" id="addTextToActiveTabEditor"><span class="type-signature"></span>addTextToActiveTabEditor<span class="signature">(text)</span><span class="type-signature"></span></h4>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="description">
|
||||
Adds given text to the editor cursor
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h5>Parameters:</h5>
|
||||
|
||||
|
||||
<table class="params">
|
||||
<thead>
|
||||
<tr>
|
||||
|
||||
<th>Name</th>
|
||||
|
||||
|
||||
<th>Type</th>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<th class="last">Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
|
||||
|
||||
<tr>
|
||||
|
||||
<td class="name"><code>text</code></td>
|
||||
|
||||
|
||||
<td class="type">
|
||||
|
||||
|
||||
<span class="param-type">string</span>
|
||||
|
||||
|
||||
|
||||
</td>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<td class="description last">this must be clear text, HTML is not supported.</td>
|
||||
</tr>
|
||||
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<dl class="details">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<dt class="important tag-deprecated">Deprecated:</dt><dd><ul class="dummy"><li>use addTextToActiveContextEditor() instead</li></ul></dd>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line328">line 328</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@ -1928,7 +2067,7 @@
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line484">line 484</a>
|
||||
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line531">line 531</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@ -2479,114 +2618,7 @@
|
||||
|
||||
|
||||
|
||||
<h4 class="name" id="getActiveNoteDetailWidget"><span class="type-signature"></span>getActiveNoteDetailWidget<span class="signature">()</span><span class="type-signature"> → {Promise.<NoteDetailWidget>}</span></h4>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="description">
|
||||
Get access to the widget handling note detail. Methods like `getWidgetType()` and `getTypeWidget()` to get to the
|
||||
implementation of actual widget type.
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<dl class="details">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line359">line 359</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h5>Returns:</h5>
|
||||
|
||||
|
||||
|
||||
|
||||
<dl>
|
||||
<dt>
|
||||
Type
|
||||
</dt>
|
||||
<dd>
|
||||
|
||||
<span class="param-type">Promise.<NoteDetailWidget></span>
|
||||
|
||||
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h4 class="name" id="getActiveTabCodeEditor"><span class="type-signature"></span>getActiveTabCodeEditor<span class="signature">()</span><span class="type-signature"> → {Promise.<CodeMirror>}</span></h4>
|
||||
<h4 class="name" id="getActiveContextCodeEditor"><span class="type-signature"></span>getActiveContextCodeEditor<span class="signature">()</span><span class="type-signature"> → {Promise.<CodeMirror>}</span></h4>
|
||||
|
||||
|
||||
|
||||
@ -2638,7 +2670,7 @@ implementation of actual widget type.
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line350">line 350</a>
|
||||
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line386">line 386</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@ -2696,7 +2728,7 @@ implementation of actual widget type.
|
||||
|
||||
|
||||
|
||||
<h4 class="name" id="getActiveTabNote"><span class="type-signature"></span>getActiveTabNote<span class="signature">()</span><span class="type-signature"> → {<a href="NoteShort.html">NoteShort</a>}</span></h4>
|
||||
<h4 class="name" id="getActiveContextNote"><span class="type-signature"></span>getActiveContextNote<span class="signature">()</span><span class="type-signature"> → {<a href="NoteShort.html">NoteShort</a>}</span></h4>
|
||||
|
||||
|
||||
|
||||
@ -2744,7 +2776,438 @@ implementation of actual widget type.
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line333">line 333</a>
|
||||
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line357">line 357</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h5>Returns:</h5>
|
||||
|
||||
|
||||
<div class="param-desc">
|
||||
active note (loaded into right pane)
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<dl>
|
||||
<dt>
|
||||
Type
|
||||
</dt>
|
||||
<dd>
|
||||
|
||||
<span class="param-type"><a href="NoteShort.html">NoteShort</a></span>
|
||||
|
||||
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h4 class="name" id="getActiveContextNotePath"><span class="type-signature"></span>getActiveContextNotePath<span class="signature">()</span><span class="type-signature"> → {Promise.<(string|null)>}</span></h4>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<dl class="details">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line412">line 412</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h5>Returns:</h5>
|
||||
|
||||
|
||||
<div class="param-desc">
|
||||
returns note path of active note or null if there isn't active note
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<dl>
|
||||
<dt>
|
||||
Type
|
||||
</dt>
|
||||
<dd>
|
||||
|
||||
<span class="param-type">Promise.<(string|null)></span>
|
||||
|
||||
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h4 class="name" id="getActiveContextTextEditor"><span class="type-signature"></span>getActiveContextTextEditor<span class="signature">()</span><span class="type-signature"> → {Promise.<CKEditor>}</span></h4>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="description">
|
||||
See https://ckeditor.com/docs/ckeditor5/latest/api/module_core_editor_editor-Editor.html for a documentation on the returned instance.
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<dl class="details">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line378">line 378</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h5>Returns:</h5>
|
||||
|
||||
|
||||
<div class="param-desc">
|
||||
instance of CKEditor
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<dl>
|
||||
<dt>
|
||||
Type
|
||||
</dt>
|
||||
<dd>
|
||||
|
||||
<span class="param-type">Promise.<CKEditor></span>
|
||||
|
||||
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h4 class="name" id="getActiveNoteDetailWidget"><span class="type-signature"></span>getActiveNoteDetailWidget<span class="signature">()</span><span class="type-signature"> → {Promise.<NoteDetailWidget>}</span></h4>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="description">
|
||||
Get access to the widget handling note detail. Methods like `getWidgetType()` and `getTypeWidget()` to get to the
|
||||
implementation of actual widget type.
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<dl class="details">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line395">line 395</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h5>Returns:</h5>
|
||||
|
||||
|
||||
|
||||
|
||||
<dl>
|
||||
<dt>
|
||||
Type
|
||||
</dt>
|
||||
<dd>
|
||||
|
||||
<span class="param-type">Promise.<NoteDetailWidget></span>
|
||||
|
||||
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h4 class="name" id="getActiveTabNote"><span class="type-signature"></span>getActiveTabNote<span class="signature">()</span><span class="type-signature"> → {<a href="NoteShort.html">NoteShort</a>}</span></h4>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<dl class="details">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<dt class="important tag-deprecated">Deprecated:</dt><dd><ul class="dummy"><li>use getActiveContextNote() instead</li></ul></dd>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line347">line 347</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@ -2838,6 +3301,8 @@ implementation of actual widget type.
|
||||
|
||||
|
||||
|
||||
<dt class="important tag-deprecated">Deprecated:</dt><dd><ul class="dummy"><li>use getActiveContextNotePath() instead</li></ul></dd>
|
||||
|
||||
|
||||
|
||||
|
||||
@ -2850,7 +3315,7 @@ implementation of actual widget type.
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line365">line 365</a>
|
||||
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line402">line 402</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@ -2908,7 +3373,7 @@ implementation of actual widget type.
|
||||
|
||||
|
||||
|
||||
<h4 class="name" id="getActiveTabTextEditor"><span class="type-signature"></span>getActiveTabTextEditor<span class="signature">(callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> → {Promise.<CKEditor>}</span></h4>
|
||||
<h4 class="name" id="getActiveTabTextEditor"><span class="type-signature"></span>getActiveTabTextEditor<span class="signature">(callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4>
|
||||
|
||||
|
||||
|
||||
@ -2975,7 +3440,7 @@ implementation of actual widget type.
|
||||
|
||||
|
||||
|
||||
<td class="description last">deprecated (use returned promise): callback receiving "textEditor" instance</td>
|
||||
<td class="description last">callback receiving "textEditor" instance</td>
|
||||
</tr>
|
||||
|
||||
|
||||
@ -3004,6 +3469,8 @@ implementation of actual widget type.
|
||||
|
||||
|
||||
|
||||
<dt class="important tag-deprecated">Deprecated:</dt><dd><ul class="dummy"><li>use getActiveContextTextEditor()</li></ul></dd>
|
||||
|
||||
|
||||
|
||||
|
||||
@ -3016,7 +3483,7 @@ implementation of actual widget type.
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line342">line 342</a>
|
||||
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line366">line 366</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@ -3041,28 +3508,6 @@ implementation of actual widget type.
|
||||
|
||||
|
||||
|
||||
<h5>Returns:</h5>
|
||||
|
||||
|
||||
<div class="param-desc">
|
||||
instance of CKEditor
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<dl>
|
||||
<dt>
|
||||
Type
|
||||
</dt>
|
||||
<dd>
|
||||
|
||||
<span class="param-type">Promise.<CKEditor></span>
|
||||
|
||||
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -3175,7 +3620,7 @@ implementation of actual widget type.
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line374">line 374</a>
|
||||
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line421">line 421</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@ -3332,7 +3777,7 @@ implementation of actual widget type.
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line426">line 426</a>
|
||||
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line473">line 473</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@ -3487,7 +3932,7 @@ implementation of actual widget type.
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line435">line 435</a>
|
||||
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line482">line 482</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@ -3749,7 +4194,7 @@ if some action needs to happen on only one specific instance.
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line453">line 453</a>
|
||||
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line500">line 500</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@ -4212,7 +4657,7 @@ otherwise (by e.g. createNoteLink())
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line416">line 416</a>
|
||||
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line463">line 463</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@ -4367,7 +4812,7 @@ otherwise (by e.g. createNoteLink())
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line444">line 444</a>
|
||||
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line491">line 491</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@ -4522,7 +4967,7 @@ otherwise (by e.g. createNoteLink())
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line462">line 462</a>
|
||||
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line509">line 509</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@ -4959,7 +5404,7 @@ otherwise (by e.g. createNoteLink())
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line386">line 386</a>
|
||||
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line433">line 433</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@ -5115,7 +5560,7 @@ otherwise (by e.g. createNoteLink())
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line397">line 397</a>
|
||||
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line444">line 444</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@ -5271,7 +5716,7 @@ otherwise (by e.g. createNoteLink())
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line406">line 406</a>
|
||||
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line453">line 453</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@ -5408,7 +5853,7 @@ otherwise (by e.g. createNoteLink())
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line511">line 511</a>
|
||||
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line558">line 558</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@ -5562,7 +6007,7 @@ otherwise (by e.g. createNoteLink())
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line502">line 502</a>
|
||||
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line549">line 549</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@ -6503,7 +6948,7 @@ Internally this serializes the anonymous function into string and sends it to ba
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line471">line 471</a>
|
||||
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line518">line 518</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@ -6654,7 +7099,7 @@ Internally this serializes the anonymous function into string and sends it to ba
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line380">line 380</a>
|
||||
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line427">line 427</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@ -7020,7 +7465,7 @@ Typical use case is when new note has been created, we should wait until it is s
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line495">line 495</a>
|
||||
<a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line542">line 542</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
@ -349,25 +349,61 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain
|
||||
/**
|
||||
* Adds given text to the editor cursor
|
||||
*
|
||||
* @deprecated use addTextToActiveContextEditor() instead
|
||||
* @param {string} text - this must be clear text, HTML is not supported.
|
||||
* @method
|
||||
*/
|
||||
this.addTextToActiveTabEditor = text => appContext.triggerCommand('addTextToActiveEditor', {text});
|
||||
this.addTextToActiveTabEditor = text => {
|
||||
console.warn("api.addTextToActiveTabEditor() is deprecated, use addTextToActiveContextEditor() instead.");
|
||||
|
||||
return appContext.triggerCommand('addTextToActiveEditor', {text});
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds given text to the editor cursor
|
||||
*
|
||||
* @param {string} text - this must be clear text, HTML is not supported.
|
||||
* @method
|
||||
*/
|
||||
this.addTextToActiveContextEditor = text => appContext.triggerCommand('addTextToActiveEditor', {text});
|
||||
|
||||
/**
|
||||
* @method
|
||||
* @deprecated use getActiveContextNote() instead
|
||||
* @returns {NoteShort} active note (loaded into right pane)
|
||||
*/
|
||||
this.getActiveTabNote = () => {
|
||||
console.warn("api.getActiveTabNote() is deprecated, use getActiveContextNote() instead.");
|
||||
|
||||
return appContext.tabManager.getActiveContextNote();
|
||||
};
|
||||
|
||||
/**
|
||||
* @method
|
||||
* @returns {NoteShort} active note (loaded into right pane)
|
||||
*/
|
||||
this.getActiveTabNote = () => appContext.tabManager.getActiveContextNote();
|
||||
this.getActiveContextNote = () => appContext.tabManager.getActiveContextNote();
|
||||
|
||||
/**
|
||||
* See https://ckeditor.com/docs/ckeditor5/latest/api/module_core_editor_editor-Editor.html for a documentation on the returned instance.
|
||||
*
|
||||
* @deprecated use getActiveContextTextEditor()
|
||||
* @method
|
||||
* @param [callback] - callback receiving "textEditor" instance
|
||||
*/
|
||||
this.getActiveTabTextEditor = callback => {
|
||||
console.warn("api.getActiveTabTextEditor() is deprecated, use getActiveContextTextEditor() instead.");
|
||||
|
||||
return appContext.tabManager.getActiveContextTextEditor(callback);
|
||||
};
|
||||
|
||||
/**
|
||||
* See https://ckeditor.com/docs/ckeditor5/latest/api/module_core_editor_editor-Editor.html for a documentation on the returned instance.
|
||||
*
|
||||
* @method
|
||||
* @param [callback] - deprecated (use returned promise): callback receiving "textEditor" instance
|
||||
* @returns {Promise<CKEditor>} instance of CKEditor
|
||||
*/
|
||||
this.getActiveTabTextEditor = callback => new Promise(resolve => appContext.triggerCommand('executeInActiveTextEditor', {callback, resolve}));
|
||||
this.getActiveContextTextEditor = () => appContext.tabManager.getActiveContextTextEditor();
|
||||
|
||||
/**
|
||||
* See https://codemirror.net/doc/manual.html#api
|
||||
@ -375,7 +411,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain
|
||||
* @method
|
||||
* @returns {Promise<CodeMirror>} instance of CodeMirror
|
||||
*/
|
||||
this.getActiveTabCodeEditor = () => new Promise(resolve => appContext.triggerCommand('executeInActiveCodeEditor', {callback: resolve}));
|
||||
this.getActiveContextCodeEditor = () => appContext.tabManager.getActiveContextCodeEditor();
|
||||
|
||||
/**
|
||||
* Get access to the widget handling note detail. Methods like `getWidgetType()` and `getTypeWidget()` to get to the
|
||||
@ -388,9 +424,20 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain
|
||||
|
||||
/**
|
||||
* @method
|
||||
* @deprecated use getActiveContextNotePath() instead
|
||||
* @returns {Promise<string|null>} returns note path of active note or null if there isn't active note
|
||||
*/
|
||||
this.getActiveTabNotePath = () => appContext.tabManager.getActiveContextNotePath();
|
||||
this.getActiveTabNotePath = () => {
|
||||
console.warn("api.getActiveTabNotePath() is deprecated, use getActiveContextNotePath() instead.");
|
||||
|
||||
return appContext.tabManager.getActiveContextNotePath();
|
||||
};
|
||||
|
||||
/**
|
||||
* @method
|
||||
* @returns {Promise<string|null>} returns note path of active note or null if there isn't active note
|
||||
*/
|
||||
this.getActiveContextNotePath = () => appContext.tabManager.getActiveContextNotePath();
|
||||
|
||||
/**
|
||||
* Returns component which owns given DOM element (the nearest parent component in DOM tree)
|
||||
|
14
package-lock.json
generated
14
package-lock.json
generated
@ -19,7 +19,7 @@
|
||||
"commonmark": "0.30.0",
|
||||
"cookie-parser": "1.4.6",
|
||||
"csurf": "1.11.0",
|
||||
"dayjs": "1.11.1",
|
||||
"dayjs": "1.11.2",
|
||||
"ejs": "3.1.7",
|
||||
"electron-debug": "3.2.0",
|
||||
"electron-dl": "3.3.1",
|
||||
@ -3200,9 +3200,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/dayjs": {
|
||||
"version": "1.11.1",
|
||||
"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.1.tgz",
|
||||
"integrity": "sha512-ER7EjqVAMkRRsxNCC5YqJ9d9VQYuWdGt7aiH2qA5R5wt8ZmWaP2dLUSIK6y/kVzLMlmh1Tvu5xUf4M/wdGJ5KA=="
|
||||
"version": "1.11.2",
|
||||
"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.2.tgz",
|
||||
"integrity": "sha512-F4LXf1OeU9hrSYRPTTj/6FbO4HTjPKXvEIC1P2kcnFurViINCVk3ZV0xAS3XVx9MkMsXbbqlK6hjseaYbgKEHw=="
|
||||
},
|
||||
"node_modules/debug": {
|
||||
"version": "4.3.3",
|
||||
@ -13413,9 +13413,9 @@
|
||||
}
|
||||
},
|
||||
"dayjs": {
|
||||
"version": "1.11.1",
|
||||
"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.1.tgz",
|
||||
"integrity": "sha512-ER7EjqVAMkRRsxNCC5YqJ9d9VQYuWdGt7aiH2qA5R5wt8ZmWaP2dLUSIK6y/kVzLMlmh1Tvu5xUf4M/wdGJ5KA=="
|
||||
"version": "1.11.2",
|
||||
"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.2.tgz",
|
||||
"integrity": "sha512-F4LXf1OeU9hrSYRPTTj/6FbO4HTjPKXvEIC1P2kcnFurViINCVk3ZV0xAS3XVx9MkMsXbbqlK6hjseaYbgKEHw=="
|
||||
},
|
||||
"debug": {
|
||||
"version": "4.3.3",
|
||||
|
@ -33,11 +33,10 @@
|
||||
"commonmark": "0.30.0",
|
||||
"cookie-parser": "1.4.6",
|
||||
"csurf": "1.11.0",
|
||||
"dayjs": "1.11.1",
|
||||
"dayjs": "1.11.2",
|
||||
"ejs": "3.1.7",
|
||||
"electron-debug": "3.2.0",
|
||||
"electron-dl": "3.3.1",
|
||||
"electron-find": "1.0.7",
|
||||
"electron-window-state": "5.0.3",
|
||||
"@electron/remote": "2.0.8",
|
||||
"express": "4.18.1",
|
||||
|
@ -48,6 +48,7 @@ import BookmarkButtons from "../widgets/bookmark_buttons.js";
|
||||
import NoteWrapperWidget from "../widgets/note_wrapper.js";
|
||||
import BacklinksWidget from "../widgets/backlinks.js";
|
||||
import SharedInfoWidget from "../widgets/shared_info.js";
|
||||
import FindWidget from "../widgets/find.js";
|
||||
|
||||
export default class DesktopLayout {
|
||||
constructor(customWidgets) {
|
||||
@ -164,6 +165,7 @@ export default class DesktopLayout {
|
||||
.child(...this.customWidgets.get('node-detail-pane'))
|
||||
)
|
||||
)
|
||||
.child(new FindWidget())
|
||||
.child(...this.customWidgets.get('center-pane'))
|
||||
)
|
||||
.child(new RightPaneContainer()
|
||||
|
@ -39,29 +39,6 @@ export default class Entrypoints extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
findInTextCommand() {
|
||||
if (!utils.isElectron()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const remote = utils.dynamicRequire('@electron/remote');
|
||||
const {FindInPage} = utils.dynamicRequire('electron-find');
|
||||
const findInPage = new FindInPage(remote.getCurrentWebContents(), {
|
||||
offsetTop: 10,
|
||||
offsetRight: 10,
|
||||
boxBgColor: 'var(--main-background-color)',
|
||||
boxShadowColor: '#000',
|
||||
inputColor: 'var(--input-text-color)',
|
||||
inputBgColor: 'var(--input-background-color)',
|
||||
inputFocusColor: '#555',
|
||||
textColor: 'var(--main-text-color)',
|
||||
textHoverBgColor: '#555',
|
||||
caseSelectedColor: 'var(--main-border-color)'
|
||||
});
|
||||
|
||||
findInPage.openFindWindow();
|
||||
}
|
||||
|
||||
async createNoteIntoInboxCommand() {
|
||||
const inboxNote = await dateNoteService.getInboxNote();
|
||||
|
||||
|
@ -321,25 +321,61 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain
|
||||
/**
|
||||
* Adds given text to the editor cursor
|
||||
*
|
||||
* @deprecated use addTextToActiveContextEditor() instead
|
||||
* @param {string} text - this must be clear text, HTML is not supported.
|
||||
* @method
|
||||
*/
|
||||
this.addTextToActiveTabEditor = text => appContext.triggerCommand('addTextToActiveEditor', {text});
|
||||
this.addTextToActiveTabEditor = text => {
|
||||
console.warn("api.addTextToActiveTabEditor() is deprecated, use addTextToActiveContextEditor() instead.");
|
||||
|
||||
return appContext.triggerCommand('addTextToActiveEditor', {text});
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds given text to the editor cursor
|
||||
*
|
||||
* @param {string} text - this must be clear text, HTML is not supported.
|
||||
* @method
|
||||
*/
|
||||
this.addTextToActiveContextEditor = text => appContext.triggerCommand('addTextToActiveEditor', {text});
|
||||
|
||||
/**
|
||||
* @method
|
||||
* @deprecated use getActiveContextNote() instead
|
||||
* @returns {NoteShort} active note (loaded into right pane)
|
||||
*/
|
||||
this.getActiveTabNote = () => {
|
||||
console.warn("api.getActiveTabNote() is deprecated, use getActiveContextNote() instead.");
|
||||
|
||||
return appContext.tabManager.getActiveContextNote();
|
||||
};
|
||||
|
||||
/**
|
||||
* @method
|
||||
* @returns {NoteShort} active note (loaded into right pane)
|
||||
*/
|
||||
this.getActiveTabNote = () => appContext.tabManager.getActiveContextNote();
|
||||
this.getActiveContextNote = () => appContext.tabManager.getActiveContextNote();
|
||||
|
||||
/**
|
||||
* See https://ckeditor.com/docs/ckeditor5/latest/api/module_core_editor_editor-Editor.html for a documentation on the returned instance.
|
||||
*
|
||||
* @deprecated use getActiveContextTextEditor()
|
||||
* @method
|
||||
* @param [callback] - callback receiving "textEditor" instance
|
||||
*/
|
||||
this.getActiveTabTextEditor = callback => {
|
||||
console.warn("api.getActiveTabTextEditor() is deprecated, use getActiveContextTextEditor() instead.");
|
||||
|
||||
return appContext.tabManager.getActiveContextTextEditor(callback);
|
||||
};
|
||||
|
||||
/**
|
||||
* See https://ckeditor.com/docs/ckeditor5/latest/api/module_core_editor_editor-Editor.html for a documentation on the returned instance.
|
||||
*
|
||||
* @method
|
||||
* @param [callback] - deprecated (use returned promise): callback receiving "textEditor" instance
|
||||
* @returns {Promise<CKEditor>} instance of CKEditor
|
||||
*/
|
||||
this.getActiveTabTextEditor = callback => new Promise(resolve => appContext.triggerCommand('executeInActiveTextEditor', {callback, resolve}));
|
||||
this.getActiveContextTextEditor = () => appContext.tabManager.getActiveContextTextEditor();
|
||||
|
||||
/**
|
||||
* See https://codemirror.net/doc/manual.html#api
|
||||
@ -347,7 +383,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain
|
||||
* @method
|
||||
* @returns {Promise<CodeMirror>} instance of CodeMirror
|
||||
*/
|
||||
this.getActiveTabCodeEditor = () => new Promise(resolve => appContext.triggerCommand('executeInActiveCodeEditor', {callback: resolve}));
|
||||
this.getActiveContextCodeEditor = () => appContext.tabManager.getActiveContextCodeEditor();
|
||||
|
||||
/**
|
||||
* Get access to the widget handling note detail. Methods like `getWidgetType()` and `getTypeWidget()` to get to the
|
||||
@ -360,9 +396,20 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain
|
||||
|
||||
/**
|
||||
* @method
|
||||
* @deprecated use getActiveContextNotePath() instead
|
||||
* @returns {Promise<string|null>} returns note path of active note or null if there isn't active note
|
||||
*/
|
||||
this.getActiveTabNotePath = () => appContext.tabManager.getActiveContextNotePath();
|
||||
this.getActiveTabNotePath = () => {
|
||||
console.warn("api.getActiveTabNotePath() is deprecated, use getActiveContextNotePath() instead.");
|
||||
|
||||
return appContext.tabManager.getActiveContextNotePath();
|
||||
};
|
||||
|
||||
/**
|
||||
* @method
|
||||
* @returns {Promise<string|null>} returns note path of active note or null if there isn't active note
|
||||
*/
|
||||
this.getActiveContextNotePath = () => appContext.tabManager.getActiveContextNotePath();
|
||||
|
||||
/**
|
||||
* Returns component which owns given DOM element (the nearest parent component in DOM tree)
|
||||
|
@ -193,6 +193,14 @@ export default class TabManager extends Component {
|
||||
return activeNote ? activeNote.type : null;
|
||||
}
|
||||
|
||||
async getActiveContextTextEditor(callback) {
|
||||
return new Promise(resolve => appContext.triggerCommand('executeInActiveTextEditor', {callback, resolve}));
|
||||
}
|
||||
|
||||
async getActiveContextCodeEditor() {
|
||||
return new Promise(resolve => appContext.triggerCommand('executeInActiveCodeEditor', {resolve}));
|
||||
}
|
||||
|
||||
async switchToNoteContext(ntxId, notePath) {
|
||||
const noteContext = this.noteContexts.find(nc => nc.ntxId === ntxId)
|
||||
|| await this.openEmptyTab();
|
||||
|
556
src/public/app/widgets/find.js
Normal file
556
src/public/app/widgets/find.js
Normal file
@ -0,0 +1,556 @@
|
||||
/**
|
||||
* Find in note replacement for Trilium ctrl+f search
|
||||
* (c) Antonio Tejada 2022
|
||||
*
|
||||
* Features:
|
||||
* - Find in writeable using ctrl+f and F3
|
||||
* - Tested on Trilium Desktop 0.50.3
|
||||
*
|
||||
* Installation:
|
||||
* - Create a code note of language JS Frontend with the contents of this file
|
||||
* - Set the owned attributes (alt-a) to #widget
|
||||
* - Set the owned attributes of any note you don't want to enable finding to
|
||||
* #noFindWidget
|
||||
* - Disable Ctrl+f shorcut in Trilium options
|
||||
*
|
||||
* Todo:
|
||||
* - Refactoring/code cleanup
|
||||
* - Case-sensitive option
|
||||
* - Regexp option
|
||||
* - Full word option
|
||||
* - Find & Replace
|
||||
*
|
||||
* Note that many times some common code is replicated between CodeMirror and
|
||||
* CKEditor codepaths because the CKEditor update is done inside a callback that
|
||||
* is deferred so the code cannot be put outside of the callback or it will
|
||||
* execute too early.
|
||||
*
|
||||
* See https://github.com/zadam/trilium/discussions/2806 for discussions
|
||||
*/
|
||||
|
||||
import NoteContextAwareWidget from "./note_context_aware_widget.js";
|
||||
import appContext from "../services/app_context.js";
|
||||
|
||||
function getNoteAttributeValue(note, attributeType, attributeName, defaultValue) {
|
||||
let attribute = note.getAttribute(attributeType, attributeName);
|
||||
|
||||
let attributeValue = (attribute != null) ? attribute.value : defaultValue;
|
||||
|
||||
return attributeValue;
|
||||
}
|
||||
|
||||
const findWidgetDelayMillis = 200;
|
||||
const waitForEnter = (findWidgetDelayMillis < 0);
|
||||
|
||||
const TEMPLATE = `<div style="contain: none;">
|
||||
<div id="findBox" style="padding: 10px; border-top: 1px solid var(--main-border-color); ">
|
||||
<input type="text" id="input">
|
||||
<input type="checkbox" id="case" disabled> case
|
||||
<input type="checkbox" id="regexp" disabled> regexp
|
||||
<span style="font-weight: bold;" id="curFound">0</span>/<span style="font-weight: bold;" id="numFound">0</span>
|
||||
</div>
|
||||
</div>`;
|
||||
|
||||
const tag = "FindWidget";
|
||||
const debugLevels = ["error", "warn", "info", "log", "debug"];
|
||||
const debugLevel = "info";
|
||||
|
||||
let warn = function() {};
|
||||
if (debugLevel >= debugLevels.indexOf("warn")) {
|
||||
warn = console.warn.bind(console, tag + ": ");
|
||||
}
|
||||
|
||||
let info = function() {};
|
||||
if (debugLevel >= debugLevels.indexOf("info")) {
|
||||
info = console.info.bind(console, tag + ": ");
|
||||
}
|
||||
|
||||
let log = function() {};
|
||||
if (debugLevel >= debugLevels.indexOf("log")) {
|
||||
log = console.log.bind(console, tag + ": ");
|
||||
}
|
||||
|
||||
let dbg = function() {};
|
||||
if (debugLevel >= debugLevels.indexOf("debug")) {
|
||||
dbg = console.debug.bind(console, tag + ": ");
|
||||
}
|
||||
|
||||
function assert(e, msg) {
|
||||
console.assert(e, tag + ": " + msg);
|
||||
}
|
||||
|
||||
function debugbreak() {
|
||||
debugger;
|
||||
}
|
||||
|
||||
|
||||
function escapeRegExp(string) {
|
||||
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||
}
|
||||
|
||||
async function getActiveContextCodeEditor() {
|
||||
return await appContext.tabManager.getActiveContextCodeEditor();
|
||||
}
|
||||
|
||||
async function getActiveContextTextEditor() {
|
||||
return await appContext.tabManager.getActiveContextTextEditor();
|
||||
}
|
||||
|
||||
// ck-find-result and ck-find-result_selected are the styles ck-editor
|
||||
// uses for highlighting matches, use the same one on CodeMirror
|
||||
// for consistency
|
||||
const FIND_RESULT_SELECTED_CSS_CLASSNAME = "ck-find-result_selected";
|
||||
const FIND_RESULT_CSS_CLASSNAME = "ck-find-result";
|
||||
|
||||
export default class FindWidget extends NoteContextAwareWidget {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
this.$widget = $(TEMPLATE);
|
||||
this.$findBox = this.$widget.find('#findBox');
|
||||
this.$input = this.$widget.find('#input');
|
||||
this.$curFound = this.$widget.find('#curFound');
|
||||
this.$numFound = this.$widget.find('#numFound');
|
||||
this.findResult = null;
|
||||
this.prevFocus = null;
|
||||
this.nedle = null;
|
||||
let findWidget = this;
|
||||
|
||||
// XXX Use api.bindGlobalShortcut?
|
||||
$(window).keydown(async function (e){
|
||||
dbg("keydown on window " + e.key);
|
||||
if ((e.key == 'F3') ||
|
||||
// Note that for ctrl+f to work, needs to be disabled in Trilium's
|
||||
// shortcut config menu
|
||||
// XXX Maybe not if using bindShorcut?
|
||||
((e.metaKey || e.ctrlKey) && ((e.key == 'f') || (e.key == 'F')))) {
|
||||
|
||||
const note = appContext.tabManager.getActiveContextNote();
|
||||
// Only writeable text and code supported
|
||||
const readOnly = note.getAttribute("label", "readOnly");
|
||||
if (!readOnly && ((note.type == "code") || (note.type == "text"))) {
|
||||
if (findWidget.$findBox.is(":hidden")) {
|
||||
|
||||
findWidget.$findBox.show();
|
||||
findWidget.$input.focus();
|
||||
findWidget.$numFound.text(0);
|
||||
findWidget.$curFound.text(0);
|
||||
|
||||
// Initialize the input field to the text selection, if any
|
||||
if (note.type == "code") {
|
||||
let codeEditor = getActiveContextCodeEditor();
|
||||
|
||||
// highlightSelectionMatches is the overlay that highlights
|
||||
// the words under the cursor. This occludes the search
|
||||
// markers style, save it, disable it. Will be restored when
|
||||
// the focus is back into the note
|
||||
findWidget.oldHighlightSelectionMatches = codeEditor.getOption("highlightSelectionMatches");
|
||||
codeEditor.setOption("highlightSelectionMatches", false);
|
||||
|
||||
// Fill in the findbox with the current selection if any
|
||||
const selectedText = codeEditor.getSelection()
|
||||
if (selectedText != "") {
|
||||
findWidget.$input.val(selectedText);
|
||||
}
|
||||
// Directly perform the search if there's some text to find,
|
||||
// without delaying or waiting for enter
|
||||
const needle = findWidget.$input.val();
|
||||
if (needle != "") {
|
||||
findWidget.$input.select();
|
||||
await findWidget.performFind(needle);
|
||||
}
|
||||
} else {
|
||||
const textEditor = await getActiveContextTextEditor();
|
||||
|
||||
const selection = textEditor.model.document.selection;
|
||||
const range = selection.getFirstRange();
|
||||
|
||||
for (const item of range.getItems()) {
|
||||
// Fill in the findbox with the current selection if
|
||||
// any
|
||||
findWidget.$input.val(item.data);
|
||||
break;
|
||||
}
|
||||
// Directly perform the search if there's some text to
|
||||
// find, without delaying or waiting for enter
|
||||
const needle = findWidget.$input.val();
|
||||
if (needle != "") {
|
||||
findWidget.$input.select();
|
||||
await findWidget.performFind(needle);
|
||||
}
|
||||
}
|
||||
}
|
||||
e.preventDefault();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
findWidget.$input.keydown(async function (e) {
|
||||
dbg("keydown on input " + e.key);
|
||||
if ((e.metaKey || e.ctrlKey) && ((e.key == 'F') || (e.key == 'f'))) {
|
||||
// If ctrl+f is pressed when the findbox is shown, select the
|
||||
// whole input to find
|
||||
findWidget.$input.select();
|
||||
} else if ((e.key == 'Enter') || (e.key == 'F3')) {
|
||||
const needle = findWidget.$input.val();
|
||||
if (waitForEnter && (findWidget.needle != needle)) {
|
||||
await findWidget.performFind(needle);
|
||||
}
|
||||
let numFound = parseInt(findWidget.$numFound.text());
|
||||
let curFound = parseInt(findWidget.$curFound.text()) - 1;
|
||||
dbg("Finding " + curFound + "/" + numFound + " occurrence of " + findWidget.$input.val());
|
||||
if (numFound > 0) {
|
||||
let delta = e.shiftKey ? -1 : 1;
|
||||
let nextFound = curFound + delta;
|
||||
// Wrap around
|
||||
if (nextFound > numFound - 1) {
|
||||
nextFound = 0;
|
||||
} if (nextFound < 0) {
|
||||
nextFound = numFound - 1;
|
||||
}
|
||||
|
||||
let needle = findWidget.$input.val();
|
||||
findWidget.$curFound.text(nextFound + 1);
|
||||
|
||||
const note = appContext.tabManager.getActiveContextNote();
|
||||
if (note.type == "code") {
|
||||
let codeEditor = getActiveContextCodeEditor();
|
||||
let doc = codeEditor.doc;
|
||||
|
||||
//
|
||||
// Dehighlight current, highlight & scrollIntoView next
|
||||
//
|
||||
|
||||
let marker = findWidget.findResult[curFound];
|
||||
let pos = marker.find();
|
||||
marker.clear();
|
||||
marker = doc.markText(
|
||||
pos.from, pos.to,
|
||||
{ "className" : FIND_RESULT_CSS_CLASSNAME }
|
||||
);
|
||||
findWidget.findResult[curFound] = marker;
|
||||
|
||||
marker = findWidget.findResult[nextFound];
|
||||
pos = marker.find();
|
||||
marker.clear();
|
||||
marker = doc.markText(
|
||||
pos.from, pos.to,
|
||||
{ "className" : FIND_RESULT_SELECTED_CSS_CLASSNAME }
|
||||
);
|
||||
findWidget.findResult[nextFound] = marker;
|
||||
|
||||
codeEditor.scrollIntoView(pos.from);
|
||||
} else {
|
||||
assert(note.type == "text", "Expected text note, found " + note.type);
|
||||
const textEditor = await getActiveContextTextEditor();
|
||||
|
||||
const model = textEditor.model;
|
||||
const doc = model.document;
|
||||
const root = doc.getRoot();
|
||||
// See
|
||||
// Parameters are callback/text, options.matchCase=false, options.wholeWords=false
|
||||
// See https://github.com/ckeditor/ckeditor5/blob/b95e2faf817262ac0e1e21993d9c0bde3f1be594/packages/ckeditor5-find-and-replace/src/findcommand.js#L44
|
||||
// XXX Need to use the callback version for regexp
|
||||
// needle = escapeRegExp(needle);
|
||||
// cufFound wrap around assumes findNext and findPrevious
|
||||
// wraparound, which is what they do
|
||||
if (delta > 0) {
|
||||
textEditor.execute('findNext', needle);
|
||||
} else {
|
||||
textEditor.execute('findPrevious', needle);
|
||||
}
|
||||
}
|
||||
}
|
||||
e.preventDefault();
|
||||
return false;
|
||||
} else if (e.key == 'Escape') {
|
||||
let numFound = parseInt(findWidget.$numFound.text());
|
||||
|
||||
const note = appContext.tabManager.getActiveContextNote();
|
||||
if (note.type == "code") {
|
||||
let codeEditor = getActiveContextCodeEditor();
|
||||
|
||||
codeEditor.focus();
|
||||
} else {
|
||||
assert(note.type == "text", "Expected text note, found " + note.type);
|
||||
const textEditor = await getActiveContextTextEditor();
|
||||
textEditor.focus();
|
||||
}
|
||||
}
|
||||
// e.preventDefault();
|
||||
});
|
||||
|
||||
findWidget.$input.on('input', function (e) {
|
||||
// XXX This should clear the previous search immediately in all cases
|
||||
// (the search is stale when waitforenter but also while the
|
||||
// delay is running for non waitforenter case)
|
||||
if (!waitForEnter) {
|
||||
// Clear the previous timeout if any, it's ok if timeoutId is
|
||||
// null or undefined
|
||||
clearTimeout(findWidget.timeoutId);
|
||||
|
||||
// Defer the search a few millis so the search doesn't start
|
||||
// immediately, as this can cause search word typing lag with
|
||||
// one or two-char searchwords and long notes
|
||||
// See https://github.com/antoniotejada/Trilium-FindWidget/issues/1
|
||||
const needle = findWidget.$input.val();
|
||||
findWidget.timeoutId = setTimeout(async function () {
|
||||
findWidget.timeoutId = null;
|
||||
await findWidget.performFind(needle);
|
||||
}, findWidgetDelayMillis);
|
||||
}
|
||||
});
|
||||
|
||||
findWidget.$input.blur(async function () {
|
||||
findWidget.$findBox.hide();
|
||||
|
||||
// Restore any state, if there's a current occurrence clear markers
|
||||
// and scroll to and select the last occurrence
|
||||
|
||||
// XXX Switching to a different tab with crl+tab doesn't invoke
|
||||
// blur and leaves a stale search which then breaks when
|
||||
// navigating it
|
||||
let numFound = parseInt(findWidget.$numFound.text());
|
||||
let curFound = parseInt(findWidget.$curFound.text()) - 1;
|
||||
const note = appContext.tabManager.getActiveContextNote();
|
||||
if (note.type == "code") {
|
||||
let codeEditor = await getActiveContextCodeEditor();
|
||||
if (numFound > 0) {
|
||||
let doc = codeEditor.doc;
|
||||
let pos = findWidget.findResult[curFound].find();
|
||||
// Note setting the selection sets the cursor to
|
||||
// the end of the selection and scrolls it into
|
||||
// view
|
||||
doc.setSelection(pos.from, pos.to);
|
||||
// Clear all markers
|
||||
codeEditor.operation(function() {
|
||||
for (let i = 0; i < findWidget.findResult.length; ++i) {
|
||||
let marker = findWidget.findResult[i];
|
||||
marker.clear();
|
||||
}
|
||||
});
|
||||
}
|
||||
// Restore the highlightSelectionMatches setting
|
||||
codeEditor.setOption("highlightSelectionMatches", findWidget.oldHighlightSelectionMatches);
|
||||
findWidget.findResult = null;
|
||||
findWidget.needle = null;
|
||||
} else {
|
||||
assert(note.type == "text", "Expected text note, found " + note.type);
|
||||
if (numFound > 0) {
|
||||
const textEditor = await getActiveContextTextEditor();
|
||||
// Clear the markers and set the caret to the
|
||||
// current occurrence
|
||||
const model = textEditor.model;
|
||||
let range = findWidget.findResult.results.get(curFound).marker.getRange();
|
||||
// From
|
||||
// https://github.com/ckeditor/ckeditor5/blob/b95e2faf817262ac0e1e21993d9c0bde3f1be594/packages/ckeditor5-find-and-replace/src/findandreplace.js#L92
|
||||
// XXX Roll our own since already done for codeEditor and
|
||||
// will probably allow more refactoring?
|
||||
let findAndReplaceEditing = textEditor.plugins.get('FindAndReplaceEditing');
|
||||
findAndReplaceEditing.state.clear(model);
|
||||
findAndReplaceEditing.stop();
|
||||
model.change(writer => {
|
||||
writer.setSelection(range, 0);
|
||||
});
|
||||
textEditor.editing.view.scrollToTheSelection();
|
||||
findWidget.findResult = null;
|
||||
findWidget.needle = null;
|
||||
} else {
|
||||
findWidget.findResult = null;
|
||||
findWidget.needle = null;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async performTextNoteFind(needle) {
|
||||
// Do this even if the needle is empty so the markers are cleared and
|
||||
// the counters updated
|
||||
const textEditor = await getActiveContextTextEditor();
|
||||
const model = textEditor.model;
|
||||
let findResult = null;
|
||||
let numFound = 0;
|
||||
let curFound = -1;
|
||||
|
||||
// Clear
|
||||
let findAndReplaceEditing = textEditor.plugins.get('FindAndReplaceEditing');
|
||||
log("findAndReplace clearing");
|
||||
findAndReplaceEditing.state.clear(model);
|
||||
log("findAndReplace stopping");
|
||||
findAndReplaceEditing.stop();
|
||||
if (needle != "") {
|
||||
// Parameters are callback/text, options.matchCase=false, options.wholeWords=false
|
||||
// See https://github.com/ckeditor/ckeditor5/blob/b95e2faf817262ac0e1e21993d9c0bde3f1be594/packages/ckeditor5-find-and-replace/src/findcommand.js#L44
|
||||
// XXX Need to use the callback version for regexp
|
||||
// needle = escapeRegExp(needle);
|
||||
// let re = new RegExp(needle, 'gi');
|
||||
// let m = text.match(re);
|
||||
// numFound = m ? m.length : 0;
|
||||
log("findAndReplace starts");
|
||||
findResult = textEditor.execute('find', needle);
|
||||
log("findAndReplace ends");
|
||||
numFound = findResult.results.length;
|
||||
// Find the result beyond the cursor
|
||||
log("findAndReplace positioning");
|
||||
let cursorPos = model.document.selection.getLastPosition();
|
||||
for (let i = 0; i < findResult.results.length; ++i) {
|
||||
let marker = findResult.results.get(i).marker;
|
||||
let fromPos = marker.getStart();
|
||||
if (fromPos.compareWith(cursorPos) != "before") {
|
||||
curFound = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
log("findAndReplace positioned");
|
||||
}
|
||||
|
||||
this.findResult = findResult;
|
||||
this.$numFound.text(numFound);
|
||||
// Calculate curfound if not already, highlight it as
|
||||
// selected
|
||||
if (numFound > 0) {
|
||||
curFound = Math.max(0, curFound);
|
||||
// XXX Do this accessing the private data?
|
||||
// See
|
||||
// https://github.com/ckeditor/ckeditor5/blob/b95e2faf817262ac0e1e21993d9c0bde3f1be594/packages/ckeditor5-find-and-replace/src/findnextcommand.js
|
||||
for (let i = 0 ; i < curFound; ++i) {
|
||||
textEditor.execute('findNext', needle);
|
||||
}
|
||||
}
|
||||
this.$curFound.text(curFound + 1);
|
||||
this.needle = needle;
|
||||
}
|
||||
|
||||
async performCodeNoteFind(needle) {
|
||||
let findResult = null;
|
||||
let numFound = 0;
|
||||
let curFound = -1;
|
||||
|
||||
// See https://codemirror.net/addon/search/searchcursor.js for tips
|
||||
let codeEditor = await getActiveContextCodeEditor();
|
||||
let doc = codeEditor.doc;
|
||||
let text = doc.getValue();
|
||||
|
||||
// Clear all markers
|
||||
if (this.findResult != null) {
|
||||
const findWidget = this;
|
||||
codeEditor.operation(function() {
|
||||
for (let i = 0; i < findWidget.findResult.length; ++i) {
|
||||
let marker = findWidget.findResult[i];
|
||||
marker.clear();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (needle != "") {
|
||||
needle = escapeRegExp(needle);
|
||||
|
||||
// Find and highlight matches
|
||||
let re = new RegExp(needle, 'gi');
|
||||
let curLine = 0;
|
||||
let curChar = 0;
|
||||
let curMatch = null;
|
||||
findResult = [];
|
||||
// All those markText take several seconds on eg this ~500-line
|
||||
// script, batch them inside an operation so they become
|
||||
// unnoticeable. Alternatively, an overlay could be used, see
|
||||
// https://codemirror.net/addon/search/match-highlighter.js ?
|
||||
codeEditor.operation(function() {
|
||||
for (let i = 0; i < text.length; ++i) {
|
||||
// Fetch next match if it's the first time or
|
||||
// if past the current match start
|
||||
if ((curMatch == null) || (curMatch.index < i)) {
|
||||
curMatch = re.exec(text);
|
||||
if (curMatch == null) {
|
||||
// No more matches
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Create a non-selected highlight marker for the match, the
|
||||
// selected marker highlight will be done later
|
||||
if (i == curMatch.index) {
|
||||
let fromPos = { "line" : curLine, "ch" : curChar };
|
||||
// XXX If multiline is supported, this needs to
|
||||
// recalculate curLine since the match may span
|
||||
// lines
|
||||
let toPos = { "line" : curLine, "ch" : curChar + curMatch[0].length};
|
||||
// XXX or css = "color: #f3"
|
||||
let marker = doc.markText( fromPos, toPos, { "className" : FIND_RESULT_CSS_CLASSNAME });
|
||||
findResult.push(marker);
|
||||
|
||||
// Set the first match beyond the cursor as current
|
||||
// match
|
||||
if (curFound == -1) {
|
||||
let cursorPos = codeEditor.getCursor();
|
||||
if ((fromPos.line > cursorPos.line) ||
|
||||
((fromPos.line == cursorPos.line) &&
|
||||
(fromPos.ch >= cursorPos.ch))){
|
||||
curFound = numFound;
|
||||
}
|
||||
}
|
||||
|
||||
numFound++;
|
||||
}
|
||||
// Do line and char position tracking
|
||||
if (text[i] == "\n") {
|
||||
curLine++;
|
||||
curChar = 0;
|
||||
} else {
|
||||
curChar++;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
this.findResult = findResult;
|
||||
this.$numFound.text(numFound);
|
||||
// Calculate curfound if not already, highlight it as selected
|
||||
if (numFound > 0) {
|
||||
curFound = Math.max(0, curFound)
|
||||
let marker = findResult[curFound];
|
||||
let pos = marker.find();
|
||||
codeEditor.scrollIntoView(pos.to);
|
||||
marker.clear();
|
||||
findResult[curFound] = doc.markText( pos.from, pos.to,
|
||||
{ "className" : FIND_RESULT_SELECTED_CSS_CLASSNAME }
|
||||
);
|
||||
}
|
||||
this.$curFound.text(curFound + 1);
|
||||
this.needle = needle;
|
||||
}
|
||||
|
||||
async performFind(needle) {
|
||||
const note = appContext.tabManager.getActiveContextNote();
|
||||
if (note.type == "code") {
|
||||
await this.performCodeNoteFind(needle);
|
||||
} else {
|
||||
assert(note.type == "text", "Expected text note, found " + note.type);
|
||||
await this.performTextNoteFind(needle);
|
||||
}
|
||||
}
|
||||
|
||||
isEnabled() {
|
||||
dbg("isEnabled");
|
||||
return super.isEnabled()
|
||||
&& ((this.note.type === 'text') || (this.note.type === 'code'))
|
||||
&& !this.note.hasLabel('noFindWidget');
|
||||
}
|
||||
|
||||
doRender() {
|
||||
dbg("doRender");
|
||||
this.$findBox.hide();
|
||||
return this.$widget;
|
||||
}
|
||||
|
||||
async refreshWithNote(note) {
|
||||
dbg("refreshWithNote");
|
||||
}
|
||||
|
||||
async entitiesReloadedEvent({loadResults}) {
|
||||
dbg("entitiesReloadedEvent");
|
||||
if (loadResults.isNoteContentReloaded(this.noteId)) {
|
||||
this.refresh();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user