|
|
|
@ -95,31 +95,32 @@ textInput = config \ ui.stateful {
|
|
|
|
|
|
|
|
|
|
|
|
# update : State \ Event \ State
|
|
|
|
# update : State \ Event \ State
|
|
|
|
update = state event \ event
|
|
|
|
update = state event \ event
|
|
|
|
| ArrowLeft \
|
|
|
|
| Key { key = c, printable = True } \
|
|
|
|
|
|
|
|
_ = debug "text keydown" c;
|
|
|
|
|
|
|
|
newText = insertChar state.text state.cursorPos c;
|
|
|
|
|
|
|
|
newCursorPos = state.cursorPos + 1;
|
|
|
|
|
|
|
|
newScroll = calcScrollOffset newText newCursorPos state.scrollOffset config.w;
|
|
|
|
|
|
|
|
newState = state.{ text = newText, cursorPos = newCursorPos, scrollOffset = newScroll };
|
|
|
|
|
|
|
|
{ state = newState, emit = [config.onChange newText] }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| Key { key = "ArrowLeft" } \
|
|
|
|
newCursorPos = max 0 (state.cursorPos - 1);
|
|
|
|
newCursorPos = max 0 (state.cursorPos - 1);
|
|
|
|
newScroll = calcScrollOffset state.text newCursorPos state.scrollOffset config.w;
|
|
|
|
newScroll = calcScrollOffset state.text newCursorPos state.scrollOffset config.w;
|
|
|
|
newState = state.{ text = state.text, cursorPos = newCursorPos, scrollOffset = newScroll };
|
|
|
|
newState = state.{ text = state.text, cursorPos = newCursorPos, scrollOffset = newScroll };
|
|
|
|
{ state = newState, emit = [config.onKeyDown] }
|
|
|
|
{ state = newState, emit = [] }
|
|
|
|
|
|
|
|
|
|
|
|
| ArrowRight \
|
|
|
|
| Key { key = "ArrowRight" } \
|
|
|
|
newCursorPos = min (len state.text) (state.cursorPos + 1);
|
|
|
|
newCursorPos = min (len state.text) (state.cursorPos + 1);
|
|
|
|
newScroll = calcScrollOffset state.text newCursorPos state.scrollOffset config.w;
|
|
|
|
newScroll = calcScrollOffset state.text newCursorPos state.scrollOffset config.w;
|
|
|
|
newState = state.{ text = state.text, cursorPos = newCursorPos, scrollOffset = newScroll };
|
|
|
|
newState = state.{ text = state.text, cursorPos = newCursorPos, scrollOffset = newScroll };
|
|
|
|
{ state = newState, emit = [config.onKeyDown] }
|
|
|
|
{ state = newState, emit = [] }
|
|
|
|
|
|
|
|
|
|
|
|
| Backspace \
|
|
|
|
| Key { key = "Backspace" } \
|
|
|
|
newText = deleteChar state.text state.cursorPos;
|
|
|
|
newText = deleteChar state.text state.cursorPos;
|
|
|
|
newCursorPos = max 0 (state.cursorPos - 1);
|
|
|
|
newCursorPos = max 0 (state.cursorPos - 1);
|
|
|
|
newScroll = calcScrollOffset newText newCursorPos state.scrollOffset config.w;
|
|
|
|
newScroll = calcScrollOffset newText newCursorPos state.scrollOffset config.w;
|
|
|
|
newState = state.{ text = newText, cursorPos = newCursorPos, scrollOffset = newScroll };
|
|
|
|
newState = state.{ text = newText, cursorPos = newCursorPos, scrollOffset = newScroll };
|
|
|
|
{ state = newState, emit = [config.onChange newText, config.onKeyDown] }
|
|
|
|
{ state = newState, emit = [config.onChange newText] }
|
|
|
|
|
|
|
|
|
|
|
|
| Char c \
|
|
|
|
|
|
|
|
newText = insertChar state.text state.cursorPos c;
|
|
|
|
|
|
|
|
newCursorPos = state.cursorPos + 1;
|
|
|
|
|
|
|
|
newScroll = calcScrollOffset newText newCursorPos state.scrollOffset config.w;
|
|
|
|
|
|
|
|
newState = state.{ text = newText, cursorPos = newCursorPos, scrollOffset = newScroll };
|
|
|
|
|
|
|
|
{ state = newState, emit = [config.onChange newText, config.onKeyDown] }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| Clicked coords \
|
|
|
|
| Clicked coords \
|
|
|
|
newCursorPos = findCursorPos state.text coords.x state.scrollOffset 8;
|
|
|
|
newCursorPos = findCursorPos state.text coords.x state.scrollOffset 8;
|
|
|
|
@ -129,7 +130,8 @@ textInput = config \ ui.stateful {
|
|
|
|
|
|
|
|
|
|
|
|
| Focused \ { state = state.{ focused = True }, emit = [] }
|
|
|
|
| Focused \ { state = state.{ focused = True }, emit = [] }
|
|
|
|
| Blurred \ { state = state.{ focused = False }, emit = [] }
|
|
|
|
| Blurred \ { state = state.{ focused = False }, emit = [] }
|
|
|
|
| event \ { state = state, emit = [config.onKeyDown event] },
|
|
|
|
| Key { key = k } \ { state = state, emit = [\ config.onKeyDown k ] }
|
|
|
|
|
|
|
|
| _ \ { state = state, emit = [] },
|
|
|
|
|
|
|
|
|
|
|
|
view = state \
|
|
|
|
view = state \
|
|
|
|
textBeforeCursor = slice state.text 0 state.cursorPos;
|
|
|
|
textBeforeCursor = slice state.text 0 state.cursorPos;
|
|
|
|
|