Fix relative path insrtion by file dropping

This commit is contained in:
1024jp 2020-10-14 09:28:05 +09:00
parent 41e8760efc
commit 0e58b0838d
5 changed files with 19 additions and 5 deletions

View File

@ -15,6 +15,7 @@ Change Log
- On sorting lines by pattern, evaluate numbers more intelligently when the “treat numbers as numeric value” option is enabled.
- Avoid discarding the current input when a new item is added while another item is in editing in the syntax style editor.
- Put only the filename rather than the absolute path for the relative path insertion (`<<<RELATIVE-PATH>>>`) when the document file itself is dropped into the editor.
- Update Python syntax style.
- [beta] Horizontally center the contents of the preferences panes (Thanks to zom-san!).
- [beta][trivial] Update the style of the add/remove buttons.

View File

@ -65,6 +65,7 @@
<li>Avoid showing the &quot;edited&quot; indicator in the close button of document windows when the document content is empty and therefore can close the window without the confirmation dialog.</li>
<li>Avoid discarding the current input when a new item is added while another item is in editing in the syntax style editor.</li>
<li>Round the corners of current line highlight.</li>
<li>Put only the filename rather than the absolute path for the relative path insertion (<code>&lt;&lt;&lt;RELATIVE-PATH&gt;&gt;&gt;</code>) when the document file itself is dropped into the editor.</li>
<li>Update Swift, SVG, Python, and Ruby syntax styles.</li>
<li>Update Shell Script syntax style (thanks to ansimita!).</li>
<li>Remove the toolbar button to toggle page guide visibility.</li>

View File

@ -65,6 +65,7 @@
<li>書類内容が空でウインドウを閉じる時確認ダイアログが表示されないときはウインドウの閉じるボタンに編集済みを示すドット記号が表示されないように変更</li>
<li>シンタックススタイルエディタで他の項目を編集中に項目を追加したとき、編集中の入力が破棄されないように変更</li>
<li>現在行ハイライトの角を丸く</li>
<li>編集している書類ファイル自身がエディタにドロップされたときも、相対パスのファイルドロップ設定 (<code>&lt;&lt;&lt;RELATIVE-PATH&gt;&gt;&gt;</code>) に対して絶対パスではなくファイル名だけを挿入</li>
<li>Swift, SVG, Python, Rubyシンタックススタイルを更新</li>
<li>Shell Scriptシンタックススタイルを更新 (ansimitaさんに感謝!)</li>
<li>ページガイドの表示を切り替えるツールバーボタンを廃止</li>

View File

@ -8,7 +8,7 @@
//
// ---------------------------------------------------------------------------
//
// © 2016-2019 1024jp
// © 2016-2020 1024jp
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -37,7 +37,11 @@ extension URL {
/// return relative-path string
func path(relativeTo baseURL: URL?) -> String? {
guard let baseURL = baseURL, baseURL != self else { return nil }
guard let baseURL = baseURL else { return nil }
if baseURL == self {
return self.lastPathComponent
}
let pathComponents = self.pathComponents
let basePathComponents = baseURL.pathComponents

View File

@ -9,7 +9,7 @@
//
// ---------------------------------------------------------------------------
//
// © 2016-2018 1024jp
// © 2016-2020 1024jp
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -35,9 +35,7 @@ final class URLExtensionsTests: XCTestCase {
let baseUrl = URL(string: "/foo/buz/file.txt")!
XCTAssertEqual(url.path(relativeTo: baseUrl), "../bar/file.txt")
XCTAssertNil(url.path(relativeTo: nil))
XCTAssertNil(url.path(relativeTo: URL(string: url.path)!))
}
@ -49,4 +47,13 @@ final class URLExtensionsTests: XCTestCase {
XCTAssertEqual(url.path(relativeTo: baseUrl), "file1.txt")
}
func testRelativeURLCreationWithSameURLs() {
let url = URL(string: "/file1.txt")!
let baseUrl = URL(string: "/file1.txt")!
XCTAssertEqual(url.path(relativeTo: baseUrl), "file1.txt")
}
}