Feature: Add Increase/Decrease Font Size Keybindings
Often I am screensharing and want to temporarily change font sizes, having a command and keybinding for that would be very helpful.
I opened this issue to hear suggestions on the best set of keybindings for these two commands.
The way it's going to work is that the font size changed will be persisted only until the Oni session ends, it should not affect the user configuration file.
After suggestions, I am willing to implement this, thanks!
As a temporary fix, I have this in my config.tsx.
// Add functions to increase and decrease font size in Oni.
// Currently it isn't persisted on purpose.
const increaseFontSize = () => {
const currentFontSize = oni.configuration.getValue(
"editor.fontSize"
) as string
let newFontSize = parseInt(currentFontSize) + FONT_STEP
oni.configuration.setValues(
{
"editor.fontSize": newFontSize,
}
)
}
const decreaseFontSize = () => {
const currentFontSize = oni.configuration.getValue(
"editor.fontSize"
) as string
let newFontSize = parseInt(currentFontSize) - FONT_STEP
newFontSize = newFontSize <= 2 ? 2 : newFontSize
oni.configuration.setValues(
{
"editor.fontSize": newFontSize,
}
)
}
// Increase font size
oni.input.bind("<c-=>", () => increaseFontSize())
// Decrease font size
oni.input.bind("<c-->", () => decreaseFontSize())
This only increases the editor.fontSize but you could easily swap it to do the ui.fontSize too.
This also isn't saved, and will revert back to default when closing Oni.
As for keybinds, I like Ctrl and =/-, but I don't know if that would cause issues on Linux. Having the above as a command for easier rebinding would be much nicer.
@CrossR Thanks for sharing, do these keybindings conflict with the ones merged from https://github.com/onivim/oni/pull/2236?
The implementation of this feature will have to take into account what is the actual computed font size in px and increase and decrease it in some delta. That's because since the configuration is a css property just converting it to int and assuming it's px can give problems with some configurations.
do these keybindings conflict with the ones merged from #2236?
Nope, I was able to do both when I tested the PR, so should be fine.
And yep thats true, I forgot we had different units for the font sizes. Mine works well as a quick hack, but it does increase the font size pretty quickly and as you say wouldn't work for anyone not using px.
Great, unless a better suggestion appears I'll use the same keybindings as yours.
Ideally we would have 3 sets of commands: for ui, for editor and for both font sizes. For the moment I'll just implement the editor font size for the sake of simplicity.
My idea is to have the current font size in a store, initialized with a default value of the configuration file and updated if the configuration file changes. The value should be stored in px, the actual computed value from the css property (I don't know if this is viable yet) and changed in deltas of 1 when the commands are called.
What about the default on OSX? Cmd++ and Cmd+- in (almost) all apps to increase decrease fontsize of the foreground app. This does not work in Oni and instead changes the mode from NORMAL to OPERATOR.