Skip to content

Instantly share code, notes, and snippets.

View zurfyx's full-sized avatar

Gerard Rovira zurfyx

View GitHub Profile
@zurfyx
zurfyx / README.md
Created July 21, 2023 18:57
Lexical Offline (Multi) Selection

The EditorState is always synced with other parties via Collab, and part of the clipboard logic.

There's times when the result should be kept strictly offline. For example:

  1. Search or multi text search (i.e. VSCode find all). Or to show GenAI GPT results.
  2. Other player cursors in Collab (not part of th EditorState)
  3. GenAI GPT Office/Notion-like popover on edit when the prompt refers to a specific part of the edit but the focus has moved to the modal.

This solution leverages Range to follow DOM updates and render on top of the Lexical editor completely independently from the editor. The MutationObserver introduced below is particularly important to make sure that the position is always up-to-date. For example, additional changes in the padding or additional added/removed nodes somewhere on the contenteditable or immediately before our selection host.

The editor dependency is very lightweight, it could easily be decoupled completely.

type LexicalNodeType2<Type> = $ReadOnly<{
type: Type,
...
}>;
export type SerializedXNode = $ReadOnly<{
// children: Array<SerializedNode>,
direction: 'ltr' | 'rtl' | null,
format: number,
indent: number,
@zurfyx
zurfyx / Invid.sol
Created February 24, 2019 16:20
InVID Rights Management Smart Contract
pragma solidity ^0.4.24;
import "./Ownable.sol";
/**
* @title Contract to register reuse requests on the InVID Rights Management site.
* @dev This contract stores the various request requests and their parties, as well as each of the
* reuse request steps that were taken during the negotiation process.
* The reuse request terms for each of the steps can be found on IPFS.
*/
@zurfyx
zurfyx / react-context-tools.js
Last active January 13, 2019 13:56
React Context Tools (provideBundle, connect, useLocalStorage)
import React, { Fragment, useState } from 'react';
/**
* Plug in many providers with a single component.
* Use:
* const Providers = provideBundle(ThemeProvider, LanguageProvider);
* <Providers>
* <YourComponent></YourComponent>
* </Providers>
*/
@zurfyx
zurfyx / xargs-parallel.sh
Last active August 15, 2018 15:35
Run commands parallelly
#!/bin/bash
# https://stackoverflow.com/a/19618159
# https://stackoverflow.com/a/51861820
#
# Example file contents:
# touch /tmp/a.txt
# touch /tmp/b.txt
if [ "$#" -eq 0 ]; then
echo "$0 <file> [max-procs=0]"
/node_modules
@zurfyx
zurfyx / App.jsx
Created December 31, 2017 20:21
GDAX-like table effect
<div className="table">
<div className="row table-header">
<div>Timestamp</div>
<div>Temperature</div>
<div>Distance</div>
</div>
{this.state.data.map((entry, i) => (
<div key={entry.timestamp} className={
`row
${i === this.state.data.length - 1 ? 'last' : '' }
# Tag last commit as 'latest'.
if [ "$TRAVIS_BRANCH" = "master" -a "$TRAVIS_PULL_REQUEST" = "false" ]; then
git config --global user.email "hi@travis-ci.org"
git config --global user.name "Sr. Travis"
git remote add release "https://${GH_TOKEN}@github.com/zurfyx/travis-android.git"
git push -d release latest
git tag -d latest
sudo: required
language: android
jdk: oraclejdk8
before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -rf $HOME/.gradle/caches/*/plugin-resolution/
cache:
sudo: required
language: android
jdk: oraclejdk8
before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -rf $HOME/.gradle/caches/*/plugin-resolution/
cache: