Skip to content
Snippets Groups Projects
Commit 087720bc authored by David Bühler's avatar David Bühler
Browse files

[ivette] SourceCode: opens the external editor at the selected character.

parent 098502ea
No related branches found
No related tags found
No related merge requests found
...@@ -39,6 +39,7 @@ import { Hfill } from 'dome/layout/boxes'; ...@@ -39,6 +39,7 @@ import { Hfill } from 'dome/layout/boxes';
import * as Path from 'path'; import * as Path from 'path';
import * as Settings from 'dome/data/settings'; import * as Settings from 'dome/data/settings';
import CodeMirror from 'codemirror/lib/codemirror';
import 'codemirror/addon/selection/active-line'; import 'codemirror/addon/selection/active-line';
import 'codemirror/addon/dialog/dialog.css'; import 'codemirror/addon/dialog/dialog.css';
import 'codemirror/addon/search/searchcursor'; import 'codemirror/addon/search/searchcursor';
...@@ -94,8 +95,13 @@ export default function SourceCode() { ...@@ -94,8 +95,13 @@ export default function SourceCode() {
React.useEffect(() => buffer.setCursorOnTop(line), [buffer, line, result]); React.useEffect(() => buffer.setCursorOnTop(line), [buffer, line, result]);
const [command] = Settings.useGlobalSettings(Preferences.EditorCommand); const [command] = Settings.useGlobalSettings(Preferences.EditorCommand);
const launchEditor = () => { const launchEditor = (_: CodeMirror.Editor, pos?: CodeMirror.Position) => {
const cmd = command.replace('%s', file).replace('%d', line.toString()); const selectedLine = pos ? (pos.line + 1).toString() : '1';
const selectedChar = pos ? (pos.ch + 1).toString() : '1';
const cmd = command
.replace('%s', file)
.replace('%n', selectedLine)
.replace('%c', selectedChar);
const args = cmd.split(' '); const args = cmd.split(' ');
const prog = args.shift(); const prog = args.shift();
if (prog) System.spawn(prog, args).catch(/* TODO */); if (prog) System.spawn(prog, args).catch(/* TODO */);
......
...@@ -131,7 +131,7 @@ export function useThemeButtons(props: ThemeProps): ThemeControls { ...@@ -131,7 +131,7 @@ export function useThemeButtons(props: ThemeProps): ThemeControls {
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
export const EditorCommand = export const EditorCommand =
new Settings.GString('Editor.Command', 'emacs +%d %s'); new Settings.GString('Editor.Command', 'emacs +%n:%c %s');
export interface EditorCommandProps { export interface EditorCommandProps {
command: Settings.GlobalSettings<string>; command: Settings.GlobalSettings<string>;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment