@@ -481,8 +481,17 @@ func GetInput(layerAlias string, styleEntry memory.TuiStyleEntryType, xLocation
481481 memory .KeyboardMemory .AddKeystrokeToKeyboardBuffer ("end" )
482482 }
483483 for currentKeyPressed != "enter" {
484+ mouseXLocation , mouseYLocation , mouseButtonPressed , _ := memory .MouseMemory .GetMouseStatus ()
485+ mouseCellIdentifier := getCellIdByLayerAlias (layerAlias , mouseXLocation , mouseYLocation )
486+ if mouseCellIdentifier != constants .NullCellId {
487+ if mouseButtonPressed == 1 {
488+ cursorPosition = mouseCellIdentifier
489+ isScreenUpdateRequired = true
490+ }
491+ }
484492 currentKeyPressed = Inkey ()
485493 if currentKeyPressed != "" {
494+ // If character is pressed.
486495 if len (currentKeyPressed ) == 1 {
487496 if len (inputString ) < maxLengthAllowed {
488497 inputString = inputString [:viewportPosition + cursorPosition ] + currentKeyPressed + inputString [viewportPosition + cursorPosition :]
@@ -583,12 +592,12 @@ func GetInput(layerAlias string, styleEntry memory.TuiStyleEntryType, xLocation
583592 }
584593 }
585594 if isScreenUpdateRequired {
586- drawInputString (layerEntry , styleEntry , xLocation , yLocation , width , 0 , stringformat .GetFilledString (width , " " ))
595+ drawInputString (layerEntry , styleEntry , xLocation , yLocation , width , 0 , false , stringformat .GetFilledString (width , " " ))
587596 if IsPasswordProtected {
588597 passwordProtectedString := stringformat .GetFilledString (len (inputString ), "*" )
589- drawInputString (layerEntry , styleEntry , xLocation , yLocation , widthOfViewport , viewportPosition , passwordProtectedString )
598+ drawInputString (layerEntry , styleEntry , xLocation , yLocation , widthOfViewport , viewportPosition , true , passwordProtectedString )
590599 } else {
591- drawInputString (layerEntry , styleEntry , xLocation , yLocation , widthOfViewport , viewportPosition , inputString )
600+ drawInputString (layerEntry , styleEntry , xLocation , yLocation , widthOfViewport , viewportPosition , true , inputString )
592601 }
593602 drawCursor (layerEntry , styleEntry , xLocation , yLocation , cursorPosition , false )
594603 UpdateDisplay ()
@@ -639,10 +648,11 @@ the text layer, then only the visible portion will be displayed.
639648start. If the remainder of your string is too long for the specified width,
640649then only the visible portion will be displayed.
641650*/
642- func drawInputString (layerEntry * memory.LayerEntryType , styleEntry memory.TuiStyleEntryType , xLocation int , yLocation int , width int , stringPosition int , inputString string ) {
651+ func drawInputString (layerEntry * memory.LayerEntryType , styleEntry memory.TuiStyleEntryType , xLocation int , yLocation int , width int , stringPosition int , isCellIdsRequired bool , inputString string ) {
643652 attributeEntry := memory .NewAttributeEntry ()
644653 attributeEntry .ForegroundColor = styleEntry .TextInputForegroundColor
645654 attributeEntry .BackgroundColor = styleEntry .TextInputBackgroundColor
655+ attributeEntry .CellType = constants .CellTypeTextInput
646656 runeSlice := []rune (inputString )
647657 var safeSubstring string
648658 if stringPosition + width <= len (inputString ) {
@@ -651,5 +661,12 @@ func drawInputString(layerEntry *memory.LayerEntryType, styleEntry memory.TuiSty
651661 safeSubstring = string (runeSlice [stringPosition : stringPosition + len (inputString )- stringPosition ])
652662 }
653663 arrayOfRunes := stringformat .GetRunesFromString (safeSubstring )
654- printLayer (layerEntry , attributeEntry , xLocation , yLocation , arrayOfRunes )
664+ // Here we loop over each character to draw since we need to accommodate for unique
665+ // cell IDs (if required for mouse location detection).
666+ for currentRuneIndex := 0 ; currentRuneIndex < len (arrayOfRunes ); currentRuneIndex ++ {
667+ if isCellIdsRequired {
668+ attributeEntry .CellId = currentRuneIndex
669+ }
670+ printLayer (layerEntry , attributeEntry , xLocation + currentRuneIndex , yLocation , []rune {arrayOfRunes [currentRuneIndex ]})
671+ }
655672}
0 commit comments