Exemplo n.º 1
0
bool editor_window_split(Win *original) {
	Win *win = window_new_file(original->editor, original->file);
	if (!win)
		return false;
	win->file = original->file;
	win->file->refcount++;
	view_syntax_set(win->view, view_syntax_get(original->view));
	view_cursor_to(win->view, view_cursor_get(original->view));
	editor_draw(win->editor);
	return true;
}
Exemplo n.º 2
0
size_t editor_window_jumplist_next(Win *win) {
	size_t cur = view_cursor_get(win->view);
	while (win->jumplist) {
		Mark mark = ringbuf_next(win->jumplist);
		if (!mark)
			return cur;
		size_t pos = text_mark_get(win->file->text, mark);
		if (pos != EPOS && pos != cur)
			return pos;
	}
	return cur;
}
Exemplo n.º 3
0
size_t editor_window_changelist_prev(Win *win) {
	size_t pos = view_cursor_get(win->view);
	if (pos != win->changelist.pos)
		win->changelist.index = 0;
	else
		win->changelist.index++;
	size_t newpos = text_history_get(win->file->text, win->changelist.index);
	if (newpos == EPOS)
		win->changelist.index--;
	else
		win->changelist.pos = newpos;
	return win->changelist.pos;
}
Exemplo n.º 4
0
Arquivo: main.c Projeto: SUMPaul/vis
static const char *cursors_new(Vis *vis, const char *keys, const Arg *arg) {
	View *view = vis_view(vis);
	size_t pos = view_cursor_get(view);
	Cursor *cursor = view_cursors_new(view);
	if (cursor) {
		view_cursors_to(cursor, pos);
		if (arg->i > 0)
			view_line_down(cursor);
		else if (arg->i < 0)
			view_line_up(cursor);
	}
	return keys;
}
Exemplo n.º 5
0
static const char *prompt_backspace(Vis *vis, const char *keys, const Arg *arg) {
	Win *prompt = vis->win;
	Text *txt = prompt->file->text;
	size_t size = text_size(txt);
	size_t pos = view_cursor_get(prompt->view);
	char c;
	if (pos == size && (pos == 1 || (size >= 2 && text_byte_get(txt, size-2, &c) && c == '\n'))) {
		prompt_restore(prompt);
		prompt_hide(prompt);
	} else {
		vis_operator(vis, VIS_OP_DELETE);
		vis_motion(vis, VIS_MOVE_CHAR_PREV);
	}
	return keys;
}
Exemplo n.º 6
0
Arquivo: vis.c Projeto: 5paceToast/vis
bool vis_window_split(Win *original) {
	Win *win = window_new_file(original->vis, original->file, UI_OPTION_STATUSBAR);
	if (!win)
		return false;
	for (size_t i = 0; i < LENGTH(win->modes); i++) {
		if (original->modes[i].bindings)
			win->modes[i].bindings = map_new();
		if (win->modes[i].bindings)
			map_copy(win->modes[i].bindings, original->modes[i].bindings);
	}
	win->file = original->file;
	win->file->refcount++;
	vis_window_syntax_set(win, vis_window_syntax_get(original));
	view_options_set(win->view, view_options_get(original->view));
	view_cursor_to(win->view, view_cursor_get(original->view));
	return true;
}
Exemplo n.º 7
0
static const char *prompt_enter(Vis *vis, const char *keys, const Arg *arg) {
	Win *prompt = vis->win;
	View *view = prompt->view;
	Text *txt = prompt->file->text;
	Win *win = prompt->parent;
	char *cmd = NULL;

	Filerange range = view_selection_get(view);
	if (!text_range_valid(&range))
		range = text_object_line(txt, view_cursor_get(view));
	if (text_range_valid(&range))
		cmd = text_bytes_alloc0(txt, range.start, text_range_size(&range));

	if (!win || !cmd) {
		vis_info_show(vis, "Prompt window invalid\n");
		prompt_restore(prompt);
		prompt_hide(prompt);
		free(cmd);
		return keys;
	}

	size_t len = strlen(cmd);
	if (len > 0 && cmd[len-1] == '\n')
		cmd[len-1] = '\0';

	bool lastline = (range.end == text_size(txt));

	prompt_restore(prompt);
	if (vis_prompt_cmd(vis, cmd)) {
		prompt_hide(prompt);
		if (!lastline) {
			text_delete(txt, range.start, text_range_size(&range));
			text_appendf(txt, "%s\n", cmd);
		}
	} else {
		vis->win = prompt;
		vis->mode = &vis_modes[VIS_MODE_INSERT];
	}
	free(cmd);
	vis_draw(vis);
	return keys;
}
Exemplo n.º 8
0
void editor_backspace_key(Editor *ed) {
	View *view = ed->win->view;
	size_t end = view_cursor_get(view);
	size_t start = view_backspace_key(view);
	editor_windows_invalidate(ed, start, end);
}
Exemplo n.º 9
0
void editor_replace_key(Editor *ed, const char *c, size_t len) {
	View *view = ed->win->view;
	size_t start = view_cursor_get(view);
	view_replace_key(view, c, len);
	editor_windows_invalidate(ed, start, start + 6);
}
Exemplo n.º 10
0
Arquivo: main.c Projeto: SUMPaul/vis
static const char *mark_set(Vis *vis, const char *keys, const Arg *arg) {
	int mark;
	keys = key2mark(vis, keys, &mark);
	vis_mark_set(vis, mark, view_cursor_get(vis_view(vis)));
	return keys;
}
Exemplo n.º 11
0
Arquivo: main.c Projeto: SUMPaul/vis
static const char *cursors_remove(Vis *vis, const char *keys, const Arg *arg) {
	View *view = vis_view(vis);
	view_cursors_dispose(view_cursor(view));
	view_cursor_to(view, view_cursor_get(view));
	return keys;
}