From 8bb21a283972b560cb72ec9c91a56f8339b0d1cf Mon Sep 17 00:00:00 2001 From: Qijia Liu Date: Sat, 9 Nov 2024 14:54:52 -0500 Subject: [PATCH] drag sort input methods; use macos-15 (#23) --- .github/workflows/ci.yml | 9 ++++++--- src/ContentView.swift | 18 +++++++++++++----- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 19e62f7..ab05e00 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,7 @@ on: jobs: lint: - runs-on: macos-14 + runs-on: macos-15 steps: - uses: actions/checkout@v4 @@ -24,7 +24,10 @@ jobs: strategy: fail-fast: false matrix: - os: [macos-14, macos-13] + os: [macos-15, macos-13] + include: + - { os: macos-15, simulator: "iPhone 16" } + - { os: macos-13, simulator: "iPhone 15" } steps: - uses: actions/checkout@v4 @@ -59,7 +62,7 @@ jobs: - name: Install run: | - xcrun simctl boot "iPhone 15" + xcrun simctl boot "${{ matrix.simulator }}" xcrun simctl install booted build/src/Release-iphonesimulator/Fcitx5.app xcrun simctl launch booted org.fcitx.Fcitx5 diff --git a/src/ContentView.swift b/src/ContentView.swift index 107a34a..47f102d 100644 --- a/src/ContentView.swift +++ b/src/ContentView.swift @@ -23,6 +23,15 @@ private class ViewModel: ObservableObject { func removeInputMethods(at offsets: IndexSet) { inputMethods.remove(atOffsets: offsets) + save() + } + + func orderInputMethods(at offsets: IndexSet, to destination: Int) { + inputMethods.move(fromOffsets: offsets, toOffset: destination) + save() + } + + private func save() { setInputMethods( String(data: try! JSONEncoder().encode(inputMethods.map { $0.name }), encoding: .utf8)!) requestReload() @@ -44,10 +53,6 @@ struct ContentView: View { setConfig(url.absoluteString, "{}") } - func removeInputMethods(at offsets: IndexSet) { - viewModel.removeInputMethods(at: offsets) - } - var body: some View { NavigationView { List { @@ -59,7 +64,10 @@ struct ContentView: View { } } if viewModel.inputMethods.count > 1 { - forEach.onDelete(perform: removeInputMethods) + forEach.onDelete { offsets in viewModel.removeInputMethods(at: offsets) } + .onMove { indices, newOffset in + viewModel.orderInputMethods(at: indices, to: newOffset) + } } else { forEach }