CodeEdit icon indicating copy to clipboard operation
CodeEdit copied to clipboard

✨ Cursor Customization

Open austincondiff opened this issue 2 years ago • 5 comments

Description

We should allow the user to customize their cursor both in the editor and in the terminal.

These customizations include:

  • Cursor shape
    • Bar
    • Underline
    • Block
  • Cursor thickness (if shape is Bar or Underline)
  • Rounded corners
  • Cursor color (active and inactive)
    • Accent Color
    • Neutral
  • Cursor transition between positions
  • Cursor blink style
    • Blink
    • Smooth
    • Phase
    • Expand
    • Solid (no blinking)

The blink styles seen in VS Code are:

Style Preview
Blink blink
Smooth blink
Phase blink smooth
Expand blink expand
Solid blink

We might experiment to offer other variations of these (maybe phase+expand for example).

I’d imagine there are many possible ways this can be configured. We might provide the following configurations, we could even use these configurations internally to create presets and then allow the user to add a custom style by playing with these values shown below.

Configuration Default (Blink) Smooth Phase Expand Solid
blink on duration 0.5s 0.5s 0.5s 0.5s 0.5s
blink off duration 0.5s 0.5s 0.5s 0.5s 0.5s
transition in duration 0s 0.05s 0.2s 0.2s 0s
transition out duration 0s 0.05s 0.2s 0.2s 0s
opacity at on state 1 1 1 1 1
opacity at off state 0 0 0 0 1
vertical scale at on state 1 1 1 1 1
vertical scale at off state 1 1 1 0 1
horizontal scale at on state 1 1 1 1 1
horizontal scale at off state 1 1 1 1 1

@CodeEditApp/maintainers What are your thoughts around this?

Considerations

This applies to both our editor which uses STTextView and the terminal which uses SwiftTerm. I've created this discussion in SwiftTerm to discuss how this might be done in coordination with their project.

austincondiff avatar Mar 07 '23 21:03 austincondiff

From the discussion in SwiftTerm by @migueldeicaza:

You could make it so that the CaretView is not just an empty box, but one that fetches the current character and draws the current character as expected. This is slightly complicated due to type setting issues (you would need to either keep the CTRun cached, or you would need to compute the CTRun for it). This has the advantage that if properly done, it would work on iOS and macOS. This might have an ugly performance hit due to having to compute the layout for every cursor movement.

This might allow for us to make the experience consistent between the editor and terminal, but we would need to consider the performance implications this might have.

austincondiff avatar Mar 07 '23 22:03 austincondiff

I just spoke with Marcin about this, he said the blinker layer is customizable with this entry point.

austincondiff avatar Mar 08 '23 00:03 austincondiff

Go ahead and add me to this issue, I'll look at that entry point for the editor and then as we learn more about both I'll implement what we can.

bombardier200 avatar Mar 08 '23 00:03 bombardier200

I wonder if we can somehow share this custom cursor view between CodeEditTextView and our terminal view or if it would be better to implement them separately.

austincondiff avatar Mar 26 '23 19:03 austincondiff

It might be possible, I was going to take a look at the cursor in CodeEditTextView this week and see what we could do to keep them consistent

bombardier200 avatar Mar 26 '23 20:03 bombardier200