From e5bb521502ef56b00a18f25aec5c7bfb6813c901 Mon Sep 17 00:00:00 2001 From: Thomas Ricouard Date: Sat, 6 Jan 2024 12:54:51 +0100 Subject: [PATCH] composer tweaks --- .../StatusEditorAccessoryView.swift | 32 ++++++++----------- .../Status/Editor/StatusEditorCoreView.swift | 21 ++++++++++++ .../Status/Editor/StatusEditorViewModel.swift | 1 + 3 files changed, 35 insertions(+), 19 deletions(-) diff --git a/Packages/Status/Sources/Status/Editor/Components/StatusEditorAccessoryView.swift b/Packages/Status/Sources/Status/Editor/Components/StatusEditorAccessoryView.swift index aff1b31a..96a899e4 100644 --- a/Packages/Status/Sources/Status/Editor/Components/StatusEditorAccessoryView.swift +++ b/Packages/Status/Sources/Status/Editor/Components/StatusEditorAccessoryView.swift @@ -60,8 +60,6 @@ struct StatusEditorAccessoryView: View { #if os(visionOS) HStack(spacing: 8) { actionsView - characterCountView - .padding(.leading, 16) } #else ScrollView(.horizontal, showsIndicators: false) { @@ -71,8 +69,6 @@ struct StatusEditorAccessoryView: View { .padding(.horizontal, .layoutPadding) } Spacer() - characterCountView - .padding(.trailing, .layoutPadding) #endif } @@ -228,6 +224,18 @@ struct StatusEditorAccessoryView: View { } } } + + Button { + viewModel.insertStatusText(text: "#") + } label: { + Image(systemName: "number") + } + + Button { + viewModel.insertStatusText(text: "@") + } label: { + Image(systemName: "at") + } Button { isLanguageSheetDisplayed.toggle() @@ -432,21 +440,7 @@ struct StatusEditorAccessoryView: View { } .presentationDetents([.medium]) } - - @ViewBuilder - private var characterCountView: some View { - let value = (currentInstance.instance?.configuration?.statuses.maxCharacters ?? 500) + focusedSEVM.statusTextCharacterLength - - Text("\(value)") - .foregroundColor(value < 0 ? .red : .secondary) - .font(.scaledCallout) - .accessibilityLabel("accessibility.editor.button.characters-remaining") - .accessibilityValue("\(value)") - .accessibilityRemoveTraits(.isStaticText) - .accessibilityAddTraits(.updatesFrequently) - .accessibilityRespondsToUserInteraction(false) - } - + private var recentlyUsedLanguages: [Language] { preferences.recentlyUsedLanguages.compactMap { isoCode in Language.allAvailableLanguages.first { $0.isoCode == isoCode } diff --git a/Packages/Status/Sources/Status/Editor/StatusEditorCoreView.swift b/Packages/Status/Sources/Status/Editor/StatusEditorCoreView.swift index 8192d159..c0e918f2 100644 --- a/Packages/Status/Sources/Status/Editor/StatusEditorCoreView.swift +++ b/Packages/Status/Sources/Status/Editor/StatusEditorCoreView.swift @@ -19,6 +19,7 @@ struct StatusEditorCoreView: View { @Environment(Theme.self) private var theme @Environment(UserPreferences.self) private var preferences @Environment(CurrentAccount.self) private var currentAccount + @Environment(CurrentInstance.self) private var currentInstance @Environment(AppAccountsManager.self) private var appAccounts @Environment(Client.self) private var client #if targetEnvironment(macCatalyst) @@ -42,6 +43,7 @@ struct StatusEditorCoreView: View { VStack(spacing: 0) { accountHeaderView textInput + characterCountView StatusEditorMediaView(viewModel: viewModel, editingMediaContainer: $editingMediaContainer) embeddedStatus pollView @@ -138,6 +140,25 @@ struct StatusEditorCoreView: View { .padding(.horizontal) } } + + + @ViewBuilder + private var characterCountView: some View { + let value = (currentInstance.instance?.configuration?.statuses.maxCharacters ?? 500) + viewModel.statusTextCharacterLength + HStack { + Spacer() + Text("\(value)") + .foregroundColor(value < 0 ? .red : .secondary) + .font(.scaledCallout) + .accessibilityLabel("accessibility.editor.button.characters-remaining") + .accessibilityValue("\(value)") + .accessibilityRemoveTraits(.isStaticText) + .accessibilityAddTraits(.updatesFrequently) + .accessibilityRespondsToUserInteraction(false) + .padding(.trailing, 8) + .padding(.bottom, 8) + } + } private func setupViewModel() { viewModel.client = client diff --git a/Packages/Status/Sources/Status/Editor/StatusEditorViewModel.swift b/Packages/Status/Sources/Status/Editor/StatusEditorViewModel.swift index 545c97aa..f3d2e0e4 100644 --- a/Packages/Status/Sources/Status/Editor/StatusEditorViewModel.swift +++ b/Packages/Status/Sources/Status/Editor/StatusEditorViewModel.swift @@ -235,6 +235,7 @@ import SwiftUI string.mutableString.insert(text, at: selectedRange.location) statusText = string selectedRange = NSRange(location: selectedRange.location + text.utf16.count, length: 0) + processText() } func replaceTextWith(text: String, inRange: NSRange) {