Code editor with Agent RX
Mandarin is a Rust code editor with Agent RX built in. Edit files directly, run commands in the terminal, or ask the agent for help in the same workspace.
The guides cover an installed Mandarin build. This site does not offer a Mandarin download yet.
1
/**
2
* One pointer, normalised to [-1, 1], damped. Read as a ref so nothing
3
* re-renders on mouse move - sections sample it inside their frame loop.
4
*/
5
import { useEffect, useRef, type MutableRefObject } from 'react'
6
7
export function usePointer(damping = 0.08, enabled = true): MutableRefObject<{ x: number; y: number }> {
8
const raw = useRef({ x: 0, y: 0 })
9
const smooth = useRef({ x: 0, y: 0 })
10
11
useEffect(() => {
12
if (!enabled) {
13
raw.current.x = 0
14
raw.current.y = 0
15
smooth.current.x = 0
16
smooth.current.y = 0
17
return
18
}
19
20
const onMove = (event: PointerEvent) => {
21
raw.current.x = (event.clientX / window.innerWidth) * 2 - 1
22
raw.current.y = 1 - (event.clientY / window.innerHeight) * 2
23
}
24
const onLeave = () => {
25
raw.current.x = 0
26
raw.current.y = 0
27
}
28
let id = 0
29
const tick = () => {
30
smooth.current.x += (raw.current.x - smooth.current.x) * damping
31
smooth.current.y += (raw.current.y - smooth.current.y) * damping
32
id = requestAnimationFrame(tick)
33
}
34
tick()
35
window.addEventListener('pointermove', onMove)
36
document.addEventListener('pointerleave', onLeave)
37
return () => {
38
cancelAnimationFrame(id)
39
window.removeEventListener('pointermove', onMove)
40
document.removeEventListener('pointerleave', onLeave)
41
}
42
}, [damping, enabled])
43
44
return smooth
45
}
1 unsaved change · Ln 6, Col 36
typescript2 spacesWork on the code, with the agent nearby.
Open your project
Use the file tree to find a file and start editing. You do not have to start the agent to make your own changes.
Ask for help in place
Keep Agent RX beside the code you are working on. Review its suggestions before keeping the changes.
Run commands nearby
Use the terminal in the same workspace instead of moving to another window for each command.
Check syntax as you edit
See syntax highlighting and syntax-error markers while you work. These are not compiler or language-server diagnostics.
Keep the file tree, search, Agent RX and terminal in one workbench. Error markers show syntax problems as you edit; check your code with your project's own build and tests.
>_
Mandarin