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 3447ae8 commit 8b7bd26
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 33 deletions.
44 changes: 12 additions & 32 deletions frontend/src/elm/Components/Diagram.elm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import Constants
import Css
exposing
( absolute
, after
, alignItems
, backgroundColor
, border3
Expand Down Expand Up @@ -79,6 +78,7 @@ import Models.Diagram.UserStoryMap as UserStoryMapModel
import Models.FontStyle as FontStyle
import Models.Item as Item exposing (Item, Items)
import Models.Item.Settings as ItemSettings
import Models.Item.Value as ItemValue
import Models.Position as Position exposing (Position)
import Models.Property as Property
import Models.Size as Size exposing (Size)
Expand Down Expand Up @@ -280,15 +280,7 @@ update model message =
(Text.lines model.text)
|> String.join "\n"
)
>> selectItem
(Just
(item
|> Item.withSettings
(Item.getSettings item
|> Maybe.map (ItemSettings.withForegroundColor (Just color))
)
)
)
>> clearSelectedItem
)
|> Maybe.withDefault Return.zero
)
Expand Down Expand Up @@ -321,15 +313,7 @@ update model message =
(Text.lines model.text)
|> String.join "\n"
)
>> selectItem
(Just
(item
|> Item.withSettings
(Item.getSettings item
|> Maybe.map (ItemSettings.withBackgroundColor (Just color))
)
)
)
>> clearSelectedItem
)
|> Maybe.withDefault Return.zero
)
Expand All @@ -343,26 +327,30 @@ update model message =
|> Maybe.map
(\item ->
let
( text, settings, comment ) =
Item.split currentText

currentText : String
currentText =
Text.getLine (Item.getLineNo item) model.text

( text, settings, comment ) =
Item.split currentText

lines : List String
lines =
Text.lines model.text

value =
ItemValue.fromString text

updateLine : String
updateLine =
item
|> Item.withText (text |> FontStyle.apply style)
|> Item.withText (ItemValue.update value (ItemValue.toTrimedString value |> FontStyle.apply style) |> ItemValue.toFullString)
|> Item.withSettings (Just settings)
|> Item.withComments comment
|> Item.toLineString
in
setText (setAt (Item.getLineNo item) updateLine lines |> String.join "\n")
>> clearSelectedItem
)
|> Maybe.withDefault Return.zero

Expand Down Expand Up @@ -417,15 +405,7 @@ update model message =
in
closeDropDown
>> setText updateText
>> selectItem
(Just
(item
|> Item.withSettings
(Item.getSettings item
|> Maybe.map (ItemSettings.withFontSize size)
)
)
)
>> clearSelectedItem
)
|> Maybe.withDefault Return.zero

Expand Down
31 changes: 30 additions & 1 deletion frontend/src/elm/Models/Item/Value.elm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module Models.Item.Value exposing
, isMarkdown
, toFullString
, toString
, toTrimedString
, update
)

Expand Down Expand Up @@ -131,7 +132,16 @@ update : Value -> String -> Value
update value text =
case value of
Markdown indent _ ->
Markdown indent <| Text.fromString text
let
rawText : String
rawText =
if String.startsWith "md:" text then
String.dropLeft 3 text

else
text
in
Markdown indent <| Text.fromString rawText

Image indent _ ->
case Url.fromString text of
Expand Down Expand Up @@ -218,6 +228,25 @@ toFullString value =
space indent ++ Text.toString text


toTrimedString : Value -> String
toTrimedString value =
case value of
Markdown _ text ->
markdownPrefix ++ Text.toString text

Image _ text ->
imagePrefix ++ Url.toString text

ImageData _ text ->
imageDataPrefix ++ DataUrl.toString text

Comment _ text ->
commentPrefix ++ Text.toString text

PlainText _ text ->
Text.toString text


toString : Value -> String
toString value =
case value of
Expand Down

0 comments on commit 8b7bd26

Please sign in to comment.