Skip to content

Commit 96e6436

Browse files
authored
feat(editor): Add keyboard shortcut to toggle word wrapping (resolves #60). (#210)
1 parent 5f7997a commit 96e6436

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/components/Editor/index.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,20 @@ const handleCopyLogEventAction = (
112112
editor.trigger(handleCopyLogEventAction.name, "editor.action.clipboardCopyAction", null);
113113
};
114114

115+
/**
116+
* Toggles the word wrap setting in the editor between "on" and "off".
117+
*
118+
* @param editor
119+
*/
120+
const handleWordWrapAction = (editor: monaco.editor.IStandaloneCodeEditor) => {
121+
const currentWordWrap = editor.getRawOptions().wordWrap;
122+
const newWordWrap = "on" === currentWordWrap ?
123+
"off" :
124+
"on";
125+
126+
editor.updateOptions({wordWrap: newWordWrap});
127+
};
128+
115129
/**
116130
* Renders a read-only editor for viewing logs.
117131
*
@@ -156,6 +170,9 @@ const Editor = () => {
156170
case ACTION_NAME.COPY_LOG_EVENT:
157171
handleCopyLogEventAction(editor, beginLineNumToLogEventNumRef.current);
158172
break;
173+
case ACTION_NAME.WORD_WRAP:
174+
handleWordWrapAction(editor);
175+
break;
159176
default:
160177
break;
161178
}

src/utils/actions.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ enum ACTION_NAME {
1313
PAGE_BOTTOM = "pageBottom",
1414
RELOAD = "reload",
1515
COPY_LOG_EVENT = "copyLogEvent",
16+
WORD_WRAP = "wordWrap",
1617
}
1718

1819
interface EditorAction {
@@ -70,6 +71,11 @@ const EDITOR_ACTIONS : EditorAction[] = [
7071
keyBindings: [monaco.KeyMod.CtrlCmd | monaco.KeyMod.Shift | monaco.KeyCode.KeyC],
7172
label: "Copy Log Event",
7273
},
74+
{
75+
actionName: ACTION_NAME.WORD_WRAP,
76+
keyBindings: [monaco.KeyMod.Alt | monaco.KeyCode.KeyZ],
77+
label: "Toggle word wrap",
78+
},
7379
];
7480

7581
type NavigationActionsMap = {

0 commit comments

Comments
 (0)