Skip to content

Commit

Permalink
Merge pull request #475 from ensan-hcl/fix/template_editor
Browse files Browse the repository at this point in the history
fix: テンプレートの編集画面でズレを負に設定しづらくなっていた問題を修正
  • Loading branch information
ensan-hcl authored Aug 21, 2024
2 parents cb4a50f + 4d99f8b commit 63e2b17
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
20 changes: 12 additions & 8 deletions MainApp/Setting/Template/TemplateEditingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ struct DateTemplateLiteralSettingView: View {
}
}

if formatSelection == "カスタム"{
if formatSelection == "カスタム" {
self.formatter.dateFormat = literal.format
self.formatter.locale = Locale(identifier: literal.language.identifier)
self.formatter.calendar = Calendar(identifier: literal.type.identifier)
Expand Down Expand Up @@ -351,8 +351,8 @@ struct DateTemplateLiteralSettingView: View {
@MainActor
private func update() {
DispatchQueue.main.async {
if formatSelection == "カスタム"{
self.date = Date().advanced(by: (Double(literal.delta) ?? .nan) * Double(literal.deltaUnit))
if formatSelection == "カスタム" {
self.date = Date().advanced(by: (Double(literal.delta) ?? 0) * Double(literal.deltaUnit))
self.template.literal = self.literal
} else {
self.date = Date()
Expand All @@ -371,7 +371,7 @@ struct DateTemplateLiteralSettingView: View {
Text(Self.yyyy_MM_dd.string(from: date)).tag("yyyy/MM/dd")
Text("カスタム").tag("カスタム")
}.onChange(of: formatSelection) {value in
if value != "カスタム"{
if value != "カスタム" {
formatter.dateFormat = value
formatter.locale = Locale(identifier: "ja_JP")
formatter.calendar = Calendar(identifier: .gregorian)
Expand All @@ -387,10 +387,15 @@ struct DateTemplateLiteralSettingView: View {

Section(header: Text("プレビュー")) {
TimelineView(.periodic(from: Date(), by: 0.5)) { _ in
Text(formatter.string(from: Date()))
if formatSelection == "カスタム" {
Text(formatter.string(from: Date().advanced(by: (Double(literal.delta) ?? 0) * Double(literal.deltaUnit))))
} else {
Text(formatter.string(from: Date()))
}
}
.monospacedDigit()
}
if formatSelection == "カスタム"{
if formatSelection == "カスタム" {
Section(header: Text("カスタム書式")) {
HStack {
Text("書式")
Expand All @@ -403,10 +408,9 @@ struct DateTemplateLiteralSettingView: View {
HStack {
Text("ズレ")
Spacer()
TextField("ズレ", text: $literal.delta)
IntegerTextField("ズレ", text: $literal.delta, range: .min ... .max)
.multilineTextAlignment(.trailing)
.textFieldStyle(.roundedBorder)
.keyboardType(.decimalPad)
.submitLabel(.done)
Picker(selection: $literal.deltaUnit, label: Text("")) {
Text("").tag(60 * 60 * 24)
Expand Down
1 change: 1 addition & 0 deletions MainApp/Setting/Template/TemplateListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ struct TemplateListView: View {
Spacer()
Text(value.item.previewString)
.foregroundStyle(.gray)
.monospacedDigit()
}
}
}
Expand Down

0 comments on commit 63e2b17

Please sign in to comment.