Code Monkey home page Code Monkey logo

vscode-text-tables's Introduction

Text Tables

version license Build Status

Text tables

VSCode extension that brings the power of Emacs table editing.

Sample

Features

  • Tables reformat
  • Easy table cells navigation
  • Support for org and markdown tables

Activation

Extension is automatically activated when you open markdown or org file. If you want to use this extension in any other file, just trigger Text Tables: Enable command in command pallete.

Commands

Extension provides several commands that are available in the Command Palette:

  • Text Tables: Enable - enable extension.
  • Text Tables: Create table - create new table in cursor position.
  • Text Tables: Format under cursor - reformat the table under cursor.
  • Text Tables: Enter table mode - enter table mode.
  • Text Tables: Exit table mode - exit table mode.
  • Text Tables: Go to next cell - switch to next cell in current table.
  • Text Tables: Go to previous cell - switch to previous cell in current table.
  • Text Tables: Clear cell - clear cell under cursor.

You can access all of the above commands from the command pallete (Ctrl+Shift+p or Cmd+Shift+p)

Table mode

Table mode is the mode where some of the default keybindings have another action assigned.

To enter table mode you may execute command Text Tables: Enter table mode from command palette or press Ctrl+q Ctrl+q shortcut to toggle mode. To control whether you're in table mode or not, see the icon in the status bar of Visual Studio Code:

Table mode status

When in table mode, Tab and Shift+Tab keybindings will navigate next/previous cell accordingly.

Navigation

Keybindings

  • Ctrl+q f - format table under cursor.
  • Ctrl+q space - clear cell under cursor.
  • Ctrl+q Ctrl+q - toggle table mode.

In table mode

  • Tab - navigate to the next cell in table.
  • Shift+Tab - navigate to the previous cell in table.

Custom keybindings

Extension introduces additional tableMode when-clause that you may use to define your own keybindings when in table mode.

Sample keybinding:

{
    "key": "tab",
    "command": "text-tables.gotoNextCell",
    "when": "tableMode"
}

Settings

This extension introduces some settings that you may setup in your user settings or workspace settings.

Available settings:

  • text-tables.mode - sets the type of tables. Valid values are: org and markdown.
  • text-tables.showStatus - controls whether to show or not status item for table mode.

Contribution

All contributions are welcome.

If you found a bug or want to propose new feature for the extension, feel free to create an issue.

vscode-text-tables's People

Contributors

rpeshkov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

vscode-text-tables's Issues

Keep table indentation level unchanged during formatting

It would be nice to keep table indentation level unchanged during formatting. I'm using the extension in the context of a language which uses tables which are nested inside other code elements. Currently, Text Tables always reformat table at the first column.

Emacs orgmode keep indentation according to the first row. So the | of the table beginning is anchored and never moves. User can explicitly indent first line to affect indentation of the whole table.

Example:

        | first | second |
  |  blah blah | this is some text |

after reformatting becomes

        | first     | second            |
        | blah blah | this is some text |

I have investigated the code today and the first idea was to keep the indentation level startCol on the table model during parsing and then indent each line by that value during stringifying. Probably navigation commands should be updated to take indentation into account. For example, pressing Tab when in the indent region should jump into the first column of that row.
Are there any gotchas I'm not aware of?

BTW, thanks for the extension. It is really helpful.

Architecture revision

Current codebase is a mess with a lot of duplications. Need to review architecture of the extension, remove duplications, extract entities, etc.

E2E tests are failing

It's been awhile since the last time I toched the extension. When using recent version of VSCode, many tests are failing during run. Error is:

Extension 'Text Tables' failed to update workspace folders:
Error: Entering a new workspace is not possible in tests.

Looks like I need to figure out how to test different configurations without creating workspace from test.

Refactor code. Cover with tests

Currently code is very messy and there is a lot of duplication. Need to reorganize it.

Also, there are no unit tests at all. Need to cover code with tests.

Conflicting with suggestions

Sometimes I need to use word suggestions provided by vscode. But I have to commit the suggested word with tab or enter. Problem is: when I'm in table mode, both tab and enter has cell-ralated functions which overrides the default suggestion-commiting. How to make this work for me?
Below is a gif of what happens after I press enter:
cannotCommitSuggestion

Rows/columns moving

In Emacs it's possible to move rows and columns of table via shortcuts:

Move column left: M-Left
Move column right: M-Right
Move row down: M-Down
Move row up: M-Up

While default VSCode shortcuts for moving rows via M-Up and M-Down fit quite good for this purpose, additional check should be done that we don't move row outside of table.

For showcase, refer to wiki

Add keybinding for table mode toggling

Currently it's possible to switch mode only through commands in command palette.

ctrl+q ctrl+q seems like good keybinding for this that should not conflict with any other.

Org-Mode table headline bug

When editing a table in org mode, the table headline is converted to markdown format
before

| Incident         | Desc                                                    | Vendor ticket | Vendor Case | Status    | Date  Closed |
|----------------+-------------------------------------------------------+-------------+-----------+---------+------------|
| [[IN1907230854]] | FL1 Battery aged and Flash module failure               | P5617KK       | TS002509957 | Closed    |              |

After inserting a new entry at bottom of table

| Incident         | Desc                                                    | Vendor ticket | Vendor Case | Status    | Date  Closed |
| ---------------- | ------------------------------------------------------- | ------------- | ----------- | --------- | ------------ |
| [[IN1907230854]] | FL1 Battery aged and Flash module failure               | P5617KK       | TS002509957 | Closed    |              |

Fix build in Travis

Build in Travis CI is currently broken because of 1 test failing

Test "Create table" for markdown:
Error: Unable to write into workspace settings because the file is dirty. Please save the workspace settings file first and then try again.

This error occurs only when running tests through npm run test.

Add command for creating new table

In Emacs it's possible to execute command org-table-create and provide table size in format NxM, where N is number of columns and M is number of rows. After pressing enter, new table is created in current cursor position. Newly created table also contain separator row after header, i.e. if you provide 2x2 as argument, newly created table will look like this:

|   |   |
|---+---|
|   |   |

Sample from emacs:
1_create_table

Create table fails for markdown

When executing command Create table in markdown mode, it fails with the following stack trace:

RangeError: Invalid count value
extensionHostProcess.js:85
	at String.repeat (native)
	at __dirname.separatorReducer.cols (/Users/rpeshkov/Developer/vscode-extensions/vscode-text-tables/out/src/ttMarkdown.js:95:48)
	at Array.reduce (native)
	at MarkdownStringifier.stringify (/Users/rpeshkov/Developer/vscode-extensions/vscode-text-tables/out/src/ttMarkdown.js:75:37)

Formatting error with double-width unicode character

For this table, the ⟺ character is double width, but the extension treats it as a single-width character, which results in an unaligned table.

How it looks:

| ¬(A ⟺ B)          | Premise |
| (A ⟹ B) ∧ (B ⟹ A) |         |
|                   |         |

How it should look:

| ¬(A ⟺ B)           | Premise |
| (A ⟹ B) ∧ (B ⟹ A) |         |
|                   |         |

Conflicting with VSCodeVim

Hello!

I use VSCodeVim and recently installed your ext. Find it very useful - thank you :) However, I can't get it work with Vim extension. My status always shows "Table Mode: Off" despite triggering "Text Tables: Enable" in command palette. It works only if I disable Vim ext. Any ideas/workarounds?

I tried the following:

    {
        "key": "ctrl+q",
        "command": "-extension.vim_ctrl+q",
    },

In hope of passthrough Vim handling. But it didn't give me anything.

Table Mode remains active after switching to other tabs

After editing table in documentation I switched to other editor tab with some code and then Tab and Shift+Tab stopped working. It took some time to understand that problem was caused by enabled table mode.

Looks like Table Mode is enabled globally in vscode after its activation.

Is it possible to bind table mode to concrete editor tab, where it was activated or maybe to markdown files only?

If that global behavior is normal, maybe add setting, that makes table mode bound to single editor tab or markdown files only.

Hide "Table Mode: Off/On" in status bar as a setting

The "Table Mode: Off/On" status at the bottom takes up a lot of room, and I don't use tables anywhere except in mark down. Is it possible to hide this status either by setting, or by file extension?

P.S.: I could attempt this myself via PR, but I want to make sure this is in alignment with your vision for this extension if I have to spend time coding it.

Implement org-table-next-row emacs command

In Emacs' org-mode there's command org-table-next-row that moves cursor to the next row or inserts new row if cursor is on last row of table. When new row inserted, cursor moves on this row, but stays in the same column.

Command is bind on Enter key.

In this extension same command should be introduced. As a shortcut Enter should be used, but it should work only in table mode.

Clear cell

Add command and shortcut for clearing cell under cursor.

For showcase refer to wiki

previousRow function is needed

First of all, thank you for having made this great extension.

I'm mapping this table generator with vscode's vim plugin, and I tried to map moving cell with h, j, k, l.

It seems not natural to exist nextRow function without previousRow function, ecpecially in this mapping. h, j, l key had been sucessfuly mapped with this extension, but k is not working well.

I checked this extension carefully, and I find there is no previousRow function.

Could you add this function for user experience?

Format under cursor causes loss of data.

Hi,

I'm running Text Tables version 0.1.5.

Given:

| A| B|
| 1| 1|
| 0| 0|
|-1|-1|

Running format will render:

| A   | B   |
| 1   | 1   |
| 0   | 0   |
| --- | --- |

Thank you.

Allow usage of extension in any file

Currently extension activated only for markdown and org files. However, this extension might be also usable in any text file. There is activation event * in vscode that makes the extension to be loaded when vscode is started, but that may harm startup time of vscode.

In order to make everyone happy, new dummy command like Text tables: Enable should be introduced and added as the activation event.

Add integration tests

Currently there are a couple of unit tests for testing of parser, stringifier, etc. Need to add integration tests, that actually create file, call commands and check the results.

escape pipes in the cell contents

Is there a way to escape pipes in the cell contents. For example when adding the below in the cell, the formatting is not correct.

awk 1 RS=" |\n"

Enable extension automatically on .txt files

How could I enable the extension automatically for my .txt files (just like with markdown and org files)?
That is:

  • witout having to go to the Command Pallete to launch the Text Tables: Enable command
  • and for all my projects (ie not in a per project basis)

Mode indicator takes up a lot of space

Compared to other mode indicators such as encoding, file format and line endings:

  1. The Table Mode: On indicator takes up a lot of space.
  • I don't think the indicator needs to appear when not in table mode
  • perhaps "Table mode" would suffice, or even "table"
  • The icon seems unnecessary unless you just use the icon on its own rather than any text
  1. It's on the wrong side of the window - it should be in the bottom right

Centered colon mark

If you write colons ':' in the divider line to indicate the column must be centered, the colons will be removed after a reformatting.

Rows/columns insert/delete

Add commands for inserting/deleting rows/columns.

In Emacs it's done via following shortcuts:
Insert row: M-S-Down
Delete row: M-S-Up
Insert column: M-S-Right
Delete column: M-S-Left

For showcase refer to wiki

Wrong behavior of handling markdown inline code block contain " | "

Hi, Peshkov

Thank you for developing such a great plugin. I found a wrong behavior of handling markdown inline code block contain " | ". Below is my software environment and reproducible steps:

  • VSCode version: 1.26.0 (4e9361)
  • Text tables extension version: 0.1.5

Reproducible steps that cause the issue

copy bellow table to vscode

| A | B |
| --- | --- |
| `a | b` | `a || b` |

then execute command Text Tables: Format under cursor(^Q ^F)

What I expected to see and what I saw instead

I expected to see

| A       | B        |
| ------- | -------- |
| `a | b` | `a || b` |

but i saw this instead

| A   | B   |     |     |     |
| --- | --- | --- | --- | --- |
| `a  | b`  | `a  |     | b`  |

Asciidoc table support

This is a feature request. It would be awsome if the extension supported Asciidoc tables as well as the existing ORG and MD tables.

Format Under Cursor within code comment?

Format under cursor successfully turns this:

|test|test2|test3|
|this is a|test not in a comment|

into this:

| test      | test2                 | test3 |
| this is a | test not in a comment |       |

Except if the table is in a code comment like this, in which case it does nothing.

// |test|test2|test3|
// |this is a|test not in a comment|

This is a feature request to support this for non-MD files.

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.