Git Product home page Git Product logo

codemirror-continue's Introduction

@valtown/codemirror-continue

This continues block comments when you hit Enter in CodeMirror.

Like when you're typing and you're here:

/**<cursor>

When you hit enter, you want it to do this:

/**
 * <cursor>

Right? Well, this CodeMirror extension does just that. It also handles the case where you're on the last line of a comment, like

/**
 * My comment
 * <cursor>

And you hit /, it'll delete the previous space, giving you

/**
 * My comment
 */

Spectacular! Get it?

Usage

Import continueKeymap:

import { continueKeymap } from "@valtown/codemirror-continue";

Import keymap and Prec:

import { Prec } from "@codemirror/state";
import { keymap } from "@codemirror/view";

Add the keybinding to your CodeMirror instance's extensions array:

extensions: [
  basicSetup,
  // … other setup
  Prec.high(keymap.of(continueKeymap)),
],

And that's it! This will only do anything if your CodeMirror is using the JavaScript or TypeScript mode.

codemirror-continue's People

Contributors

tmcw avatar

Stargazers

Jin Yao avatar Cameron Kelley avatar Hatem Hosny avatar Raphaël Améaume avatar Huy Giang avatar Javel Rowe avatar Ben Williams avatar Chauncey McAskill avatar Orange Mug avatar Andrew Chou avatar Ilya Radchenko avatar  avatar

Watchers

 avatar André Vitor Terron avatar Steve Krouse avatar

codemirror-continue's Issues

Continue C++-style comments

// Comment<enter>

This could / should end up with

// Comment
// <cursor>

I think this is kind of opinionated, so it might make sense to make it optional.

Support mid-line Enter

In this situation

/**
 * Comment
 * Something <cursor> something else
 */

It'd be nice for Enter to produce:

/**
 * Comment
 * Something
 * something else
 */

This should handle all of the properties of our existing continue system - it'll preserve surrounding indentation, so if this comment inside of a function so it's indented 2 or 4 spaces, it should preserve that. Plus, we may want to truncate the whitespace at the end of the line? That's optional.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.