Add different modes
Merged
Some optimization
Fix text selection bug with negative indices