Exemplo n.º 1
0
/* Exported function documented in search.h */
void search_show_all(bool all, struct search_context *context)
{
	struct list_entry *a;

	for (a = context->found->next; a; a = a->next) {
		bool add = true;
		if (!all && a != context->current) {
			add = false;
			if (a->sel) {
				selection_clear(a->sel, true);
				selection_destroy(a->sel);
				a->sel = NULL;
			}
		}
		if (add && !a->sel) {

			if (context->is_html == true) {
				html_content *html = (html_content *)context->c;
				a->sel = selection_create(context->c, true);
				if (!a->sel)
					continue;

				selection_init(a->sel, html->layout,
						&html->len_ctx);
			} else {
				a->sel = selection_create(context->c, false);
				if (!a->sel)
					continue;

				selection_init(a->sel, NULL, NULL);
			}

			selection_set_start(a->sel, a->start_idx);
			selection_set_end(a->sel, a->end_idx);
		}
	}
}
Exemplo n.º 2
0
// process the key
void ProcessKey(EditView *ev, int key)
{
uint flags = GetKeyAttr(key);
char MergeToPrior;

	// free xseek mode
	if (ev->cursor.xseekmode != CM_FREE)
	{
		switch(key)
		{
			// these need to maintain the state of the CM_WANT_SCREEN_COORD coordinate
			case B_UP_ARROW:
			case B_DOWN_ARROW:
			case B_PAGE_UP:
			case B_PAGE_DOWN: break;
			
			default: ev->cursor.set_mode(CM_FREE);
		}
	}
	
	// commands which delete selection & contents if a selection is present
	if (flags & KF_SELDEL)
	{
		if (ev->selection.present)
		{
			ev->SelDel();
			
			if (flags & KF_SELDEL_ONLY)
				return;
		}
	}
	
	// create new undo group before executing keys which modify the document
	if (flags & KF_UNDOABLE)
	{
		if (flags & KF_UNDO_MERGEABLE)
		{
			MergeToPrior = undo_can_merge(ev, ev->cursor.x, ev->cursor.y, key);
			
			if (!MergeToPrior)
				BeginUndoGroup(ev);
		}
		else
		{
			MergeToPrior = 0;
			BeginUndoGroup(ev);
		}
	}
	
	if (flags & KF_AFFECTS_SELECTION)	// key can create/remove selection
	{
		if (IsShiftDown() && !ev->selection.present)
			selection_create(ev);
	}
	
	switch(key)
	{
		case B_ESCAPE:
			if (editor.settings.esc_quits_immediately)	// a testmode
			{
				MainWindow->fDoingInstantQuit = true;
				be_app->PostMessage(B_QUIT_REQUESTED);
			}
		break;
		
		case B_LEFT_ARROW: ev->cursor.left(); break;
		case B_RIGHT_ARROW: ev->cursor.right(); break;
		case B_UP_ARROW: ev->cursor.up(); break;
		case B_DOWN_ARROW: ev->cursor.down(); break;
		
		case B_PAGE_DOWN: ev->cursor.pgdn(); break;
		case B_PAGE_UP: ev->cursor.pgup(); break;
		
		case B_HOME: DoHome(ev); break;
		case B_END: DoEnd(ev); break;
		
		case KEY_MOUSEWHEEL_DOWN: ev->scroll_down(3); break;
		case KEY_MOUSEWHEEL_UP: ev->scroll_up(3); break;
		
		case B_ENTER:
			DoEnter(ev);
			editor.stats.CRs_typed++;
			editor.stats.keystrokes_typed++;
		break;
		
		case B_TAB:
		{
			if (IsShiftDown())
			{
				DoShiftTab(ev);
				break;
			}
			
			if (DoTabIndent(ev)) break;
			
			ev->SelDel();
			ev->action_insert_char(ev->cursor.x, ev->cursor.y, TAB);
			ev->cursor.x++;
			
			editor.stats.keystrokes_typed++;
		}
		break;
		
		// BKSP is equivalent to left followed by del
		case B_BACKSPACE:
			if (!ev->cursor.y && !ev->cursor.x) break;
			
			ev->cursor.left();
			
			undo_SetMergeMode(ev, MERGE_BKSP, MergeToPrior);
			ev->action_delete_right(ev->cursor.x, ev->cursor.y, 1);
			editor.stats.keystrokes_typed++;
		break;
		
		case B_DELETE:
			undo_SetMergeMode(ev, MERGE_DEL, MergeToPrior);
			ev->action_delete_right(ev->cursor.x, ev->cursor.y, 1);
			editor.stats.keystrokes_typed++;
		break;
		
		// typing
		default:
		{
			// ignore non-printable keystrokes
			if (key > 127 || key < 9)
				break;
			
			if (editor.InOverwriteMode && \
				ev->cursor.x < ev->curline->GetLength())
			{
				// less than ideal: i wasn't planning on Overwrite Mode when writing
				// the undo feature, so it can't merge undo records that contain both a
				// delete and a insertion. OVR mode isn't used much and undo still works,
				// just one char at a time, so I think it's ok for now but eventually should
				// be looked at.
				if (MergeToPrior)
				{
					MergeToPrior = false;
					BeginUndoGroup(ev);
				}
				
				ev->action_delete_right(ev->cursor.x, ev->cursor.y, 1);
			}
			else
			{
				undo_SetMergeMode(ev, MERGE_TYPING, MergeToPrior);
			}
			
			ev->action_insert_char(ev->cursor.x, ev->cursor.y, key);
			ev->cursor.x++;
			editor.stats.keystrokes_typed++;
		}
		break;
	}
	
	// smart indent (for close quotes)
	if (key == '}' && editor.settings.smart_indent_on_close)
		CloseSmartIndent(ev);
	
	if (flags & KF_AFFECTS_SELECTION)
		ev->ExtendOrDropSel(key);
	
	if (flags & KF_UNDOABLE)
	{
		if (MergeToPrior)
			UpdateMergedUndoGroup(ev);
		else
			EndUndoGroup(ev);
	}
	
	if (!(flags & KF_NO_VIEW_TO_CURSOR))
	{
		ev->MakeCursorVisible();
	}
}