/* Insert a row into the full-text index; set *piRowid to be the ID of the * new row. */ static int index_insert(fulltext_vtab *v, sqlite3_value *pRequestRowid, const char *zText, sqlite_int64 *piRowid){ Hash terms; /* maps term string -> PosList */ HashElem *e; int rc = content_insert(v, pRequestRowid, zText, -1); if( rc!=SQLITE_OK ) return rc; *piRowid = sqlite3_last_insert_rowid(v->db); if( !zText ) return SQLITE_OK; /* nothing to index */ rc = build_terms(&terms, v->pTokenizer, zText, *piRowid); if( rc!=SQLITE_OK ) return rc; for(e=HashFirst(&terms); e; e=HashNext(e)){ DocList *p = HashData(e); rc = index_insert_term(v, HashKey(e), HashKeysize(e), *piRowid, p); if( rc!=SQLITE_OK ) break; } for(e=HashFirst(&terms); e; e=HashNext(e)){ DocList *p = HashData(e); docListDelete(p); } HashClear(&terms); return rc; }
void BasicGrid::content_action( UI::ProtoGrid::ContentAction action, UI::index_type row_begin, UI::index_type count ) noexcept { using CA = UI::ProtoGrid::ContentAction; DUCT_ASSERTE(row_count() == signed_cast(m_sel.size())); // Cast insert_after in terms of insert_before if (CA::insert_after == action) { ++row_begin; } row_begin = value_clamp(row_begin, 0, row_count()); auto const row_end = min_ce(row_begin + count, row_count()); auto clear_flag = UI::UpdateActions::none; switch (action) { // Select case CA::select: // fall-through case CA::unselect: { bool const enable = CA::select == action; auto const end = m_sel.begin() + row_end; for (auto it = m_sel.begin() + row_begin; end > it; ++it) { *it = enable; } queue_cell_render(row_begin, row_end); clear_flag = UI::UpdateActions::flag_noclear; } break; case CA::select_toggle: { auto const end = m_sel.begin() + row_end; for (auto it = m_sel.begin() + row_begin; end > it; ++it) { *it = !*it; } queue_cell_render(row_begin, row_end); clear_flag = UI::UpdateActions::flag_noclear; } break; // Insert case CA::insert_after: // fall-through case CA::insert_before: for (UI::index_type i = 0; i < count; ++i) { if (content_insert(row_begin + i)) { m_sel.insert(m_sel.begin() + row_begin + i, false); content_action_internal(CA::insert_before, row_begin + i, 1); } } if (row_count() == 1) { set_cursor(m_cursor.col, 0); } else if (row_begin <= m_cursor.row) { set_cursor(m_cursor.col, m_cursor.row + count); } adjust_view(); break; // Erase case CA::erase: for (UI::index_type i = 0; i < count; ++i) { if (content_erase(row_begin)) { m_sel.erase(m_sel.cbegin() + row_begin); content_action_internal(CA::erase, row_begin, 1); } } break; case CA::erase_selected: for (UI::index_type index = 0; index < row_count();) { if (m_sel[index] && content_erase(index)) { m_sel.erase(m_sel.cbegin() + index); content_action_internal(CA::erase, index, 1); } else { ++index; } } break; } // switch (action) // Post action switch (action) { case CA::erase: case CA::erase_selected: // Let cursor clamp to new bounds set_cursor(m_cursor.col, m_cursor.row); adjust_view(); break; default: break; } enqueue_actions( UI::UpdateActions::render | clear_flag ); }