I have a view that can change the layout depending if there is only one item in the array or multiple.
fn node_view_content(state: State) {
fn(node: display.Node, parent: Option(display.Node), path: board.Path) -> Result(
List(element.Element(state.Msg)),
Nil,
) {
use meta <- result.try(dict.get(state.board.metanodes, node.id))
case parent, iv.length(node.data.rows) {
_parent, 1 -> columns_view(state, node, meta, path)
Some(parent), _rows -> rows_view(state, node, meta, parent, path)
None, _rows -> Error(Nil)
}
}
}
inside the rows_view and columns_view there is a search bar. If the user is typing and there is only 1 row left it will switch view from rows_view into columns_view.
I can manually return an effect where I refocus the search bar, however I also need to store state to make sure the cursor maintains the same position in the text input.
so for instance the search bar contains : "glleam" and you remove one character: "gleam" the cursor should maintain to be positioned like this: "gl" (cursor here) "eam" .
Is there a better way of remaining focus so I won't have to maintain the state of the cursor index?