From 2687fdbf97854c9fdcba9832a92eb9c45737ae40 Mon Sep 17 00:00:00 2001 From: harehare Date: Wed, 27 Dec 2023 22:56:47 +0900 Subject: [PATCH] :bug: Fix edit bugs --- frontend/src/elm/Components/Diagram.elm | 47 ++++++++++++------- frontend/src/elm/Extension/Lib.elm | 4 +- .../src/elm/Views/Diagram/ContextMenu.elm | 2 +- frontend/src/elm/Views/Diagram/Views.elm | 2 +- 4 files changed, 35 insertions(+), 20 deletions(-) diff --git a/frontend/src/elm/Components/Diagram.elm b/frontend/src/elm/Components/Diagram.elm index 9e01000a0..fdda05867 100644 --- a/frontend/src/elm/Components/Diagram.elm +++ b/frontend/src/elm/Components/Diagram.elm @@ -6,6 +6,7 @@ import Constants import Css exposing ( absolute + , after , alignItems , backgroundColor , border3 @@ -48,7 +49,7 @@ import Html.Styled.Events as Event import Html.Styled.Lazy as Lazy import Json.Decode as D import List -import List.Extra exposing (getAt, setAt) +import List.Extra as ListEx exposing (getAt, setAt) import Maybe import Models.Color as Color import Models.Diagram as Diagram exposing (DragStatus(..), Model, Msg(..), SelectedItem, dragStart) @@ -186,7 +187,7 @@ update model message = >> clearPosition EditSelectedItem text -> - Return.map <| \m -> { m | selectedItem = Maybe.map (\item_ -> item_ |> Item.withTextOnly (" " ++ String.trimLeft text)) m.selectedItem } + Return.map <| \m -> { m | selectedItem = Maybe.map (\item_ -> item_ |> Item.withTextOnly (String.trimLeft text)) m.selectedItem } EndEditSelectedItem item -> model.selectedItem @@ -197,20 +198,34 @@ update model message = lines = Text.lines model.text - text : String - text = - setAt (Item.getLineNo item) - (item - |> Item.withSettings - (Item.getSettings selectedItem) - |> Item.toLineString - |> String.dropLeft 1 - ) - lines - |> String.join "\n" + beforeText = + Item.new + |> (ListEx.getAt (Item.getLineNo item) lines + |> Maybe.map String.trim + |> Maybe.withDefault "" + |> Item.withText + ) + |> Item.getTextOnly + + afterText = + Item.getTextOnly selectedItem in - setText text - >> clearSelectedItem + if beforeText == afterText then + clearSelectedItem + + else + let + text : String + text = + setAt (Item.getLineNo item) + (item + |> Item.withSettings (Item.getSettings selectedItem) + |> Item.toLineString + ) + lines + |> String.join "\n" + in + setText text >> clearSelectedItem ) |> Maybe.withDefault Return.zero @@ -1424,7 +1439,7 @@ svgView model centerPosition (( svgWidth, svgHeight ) as svgSize) mainSvg = else ( floor <| toFloat (Position.getX pos) * Scale.toFloat (model.settings.scale |> Maybe.withDefault Scale.default) - , floor <| toFloat (Position.getY pos + h + 24) * Scale.toFloat (model.settings.scale |> Maybe.withDefault Scale.default) + , floor <| toFloat (Position.getY pos + h) * Scale.toFloat (model.settings.scale |> Maybe.withDefault Scale.default) ) ( _, h ) = diff --git a/frontend/src/elm/Extension/Lib.elm b/frontend/src/elm/Extension/Lib.elm index 3165a8f2c..f70bdff42 100644 --- a/frontend/src/elm/Extension/Lib.elm +++ b/frontend/src/elm/Extension/Lib.elm @@ -7,7 +7,7 @@ import Html.Styled as Html exposing (Html, div) import Html.Styled.Attributes exposing (style) import Html.Styled.Lazy exposing (lazy) import Json.Decode as D -import Models.Color exposing (Color) +import Models.Color as Color exposing (Color) import Models.Diagram as DiagramModel import Models.Diagram.CardSize as CardSize import Models.Diagram.Data as DiagramData @@ -126,7 +126,7 @@ update (UpdateDiagram subMsg) model = view : Model -> Html Msg view model = div - [ style "background-color" model.backgroundColor + [ style "background-color" <| Color.toString model.backgroundColor ] [ div [ style "display" "flex" diff --git a/frontend/src/elm/Views/Diagram/ContextMenu.elm b/frontend/src/elm/Views/Diagram/ContextMenu.elm index 881eced09..69d83c140 100644 --- a/frontend/src/elm/Views/Diagram/ContextMenu.elm +++ b/frontend/src/elm/Views/Diagram/ContextMenu.elm @@ -182,7 +182,7 @@ view width display props = Svg.foreignObject [ SvgAttr.class "context-menu" , Attributes.dataTest "context-menu" - , SvgAttr.x <| String.fromInt <| Position.getX props.position + , SvgAttr.x <| String.fromInt <| (Position.getX props.position - 8) , SvgAttr.y <| String.fromInt <| (Position.getY props.position + 8) , SvgAttr.width "320" , SvgAttr.height "285" diff --git a/frontend/src/elm/Views/Diagram/Views.elm b/frontend/src/elm/Views/Diagram/Views.elm index b4cdbfbb6..9f000e3d0 100644 --- a/frontend/src/elm/Views/Diagram/Views.elm +++ b/frontend/src/elm/Views/Diagram/Views.elm @@ -244,7 +244,7 @@ inputBase { settings, fontSize, position, size, color, item, fontWeight, onEditS [ outline none ] ] - , Attr.value <| " " ++ String.trimLeft (Item.getMultiLineText item) + , Attr.value <| String.trimLeft (Item.getMultiLineText item) , onInput onEditSelectedItem , onBlur <| onSelect Nothing , Events.onEnter <| onEndEditSelectedItem item