Add smarten quotes and straighten quotes commands (#1092, #1107)

This commit is contained in:
1024jp 2020-09-26 22:15:20 +09:00
parent 464f8c0f7c
commit 24644f28ad
7 changed files with 99 additions and 0 deletions

View File

@ -5,6 +5,11 @@ Change Log
4.0.0-beta.3 (unreleased)
--------------------------
### New Features
- Add new AppleScript/JXA commands `smarten quotes` and `straighten quotes` for selection object.
### Improvements
- [beta] Horizontally center the contents of the preferences panes (Thanks to zom-san!).

View File

@ -439,6 +439,26 @@ For example, when not using the <code>wrap</code> or <code>backwards</code> opti
</section>
<section>
<h3>smart quotes</h3>
<dl class="tree">
<dt><code class="command">smarten quotes</code></dt>
<dd>Convert straight quotes in the selected text to typographical quotes if exists. <span class="added">new on CotEditor 4.0.0</span></dd>
<dt><code class="command">straighten quotes</code></dt>
<dd>Convert typographical quotes in the selected text to straight quotes if exists. <span class="added">new on CotEditor 4.0.0</span></dd>
</dl>
<p>Works only for selection objects.</p>
<figure>
<pre class="source"><code class="AppleScript">smarten quotes selection of front document</code></pre>
<figcaption>Convert straight quotes in the selected text to typographical quotes.</figcaption>
</figure>
</section>
<section>
<h3>normalize unicode</h3>

View File

@ -17,6 +17,17 @@
<h1>Change log of AppleScript support</h1>
<article>
<h2>Terminology change on CotEditor 4.0.0</h2>
<h3>smart quotes</h3>
<p>The following new commands were added to the selection object.</p>
<ul class="nostyle">
<li><code>smarten quotes</code></li>
<li><code>straighten quotes</code></li>
</ul>
</article>
<article>
<h2>Terminology change on CotEditor 3.5.0</h2>
<h3>editor's opacity</h3>

View File

@ -438,6 +438,26 @@ lengthが負である場合、指定される範囲は対象ドキュメント
</section>
<section>
<h3>スマート引用符</h3>
<dl class="tree">
<dt><code class="command">smarten quotes</code></dt>
<dd>まっすぐな引用符をカールした引用符に変更する。<span class="added">CotEditor 4.0.0で追加</span></dd>
<dt><code class="command">straighten quotes</code></dt>
<dd>カールした引用符をまっすぐな引用符に変更する。<span class="added">CotEditor 4.0.0で追加</span></dd>
</dl>
<p>対象にできるのは`selection`オブジェクトだけです。</p>
<figure>
<pre class="source"><code class="AppleScript">smarten quotes selection of front document</code></pre>
<figcaption>選択位置の引用符をカールしたものに変換する。</figcaption>
</figure>
</section>
<section>
<h3>normalize unicode</h3>

View File

@ -17,6 +17,19 @@
<h1>AppleScript対応の仕様改訂履歴</h1>
<article>
<h2>CotEditor 4.0.0での仕様改訂</h2>
<section>
<h3>スマート引用符</h3>
<p>selectionオブジェクトに新しく以下のコマンドが追加されました。</p>
<ul class="nostyle">
<li><code>smarten quotes</code></li>
<li><code>straighten quotes</code></li>
</ul>
</section>
</article>
<article>
<h2>CotEditor 3.5.0での仕様改訂</h2>
<h3>エディタの不透明度</h3>

View File

@ -146,6 +146,12 @@
<responds-to command="uncomment">
<cocoa method="handleUncomment:"/>
</responds-to>
<responds-to command="smarten quotes">
<cocoa method="handleSmartenQuotes:"/>
</responds-to>
<responds-to command="straighten quotes">
<cocoa method="handleStraightenQuotes:"/>
</responds-to>
<responds-to command="normalize unicode">
<cocoa method="handleNormalizeUnicode:"/>
</responds-to>
@ -311,6 +317,16 @@
<result type="text"/>
</command>
<command name="smarten quotes" code="cEd1SmQt" description="Convert straight quotes to typographical quotes.">
<access-group identifier="com.coteditor.CotEditor.edit" access="rw"/>
<direct-parameter type="text selection" description="The selection to normalize."/>
</command>
<command name="straighten quotes" code="cEd1StQt" description="Convert typographical quotes to straight quotes.">
<access-group identifier="com.coteditor.CotEditor.edit" access="rw"/>
<direct-parameter type="text selection" description="The selection to normalize."/>
</command>
<command name="normalize unicode" code="cEd1UNml" description="Normalize Unicode.">
<access-group identifier="com.coteditor.CotEditor.edit" access="rw"/>
<direct-parameter type="text selection" description="The selection to normalize."/>

View File

@ -307,6 +307,20 @@ final class TextSelection: NSObject {
}
/// convert straight quotes to typographical pairs
@objc func handleSmartenQuotes(_ command: NSScriptCommand) {
self.textView?.perform(Selector(("replaceQuotesInSelection:")))
}
/// convert typographical (curly) quotes to straight
@objc func handleStraightenQuotes(_ command: NSScriptCommand) {
self.textView?.straightenQuotesInSelection(command)
}
/// Unicode normalization
@objc func handleNormalizeUnicode(_ command: NSScriptCommand) {