Skip to content

Commit

Permalink
🐛 Fix edit bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
harehare committed Dec 27, 2023
1 parent e9922c0 commit 2687fdb
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 20 deletions.
47 changes: 31 additions & 16 deletions frontend/src/elm/Components/Diagram.elm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Constants
import Css
exposing
( absolute
, after
, alignItems
, backgroundColor
, border3
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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 ) =
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/elm/Extension/Lib.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/elm/Views/Diagram/ContextMenu.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/elm/Views/Diagram/Views.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2687fdb

Please sign in to comment.