create 1-line code area

Hi, what is the best way to create a code area with only 1-line. i.e. Enter wont create a new line.
Thanks.

In version 5.x, use the beforeChange event, in 6.x, use a transactionFilter, to prevent any changes that insert a newline.

1 Like

Thanks. What is the best way to map from Transaction to TransactionSpec.
I am thinking using transaction.changes.iterChanges((fromA, toA, fromB, toB, inserted)=>{convert to TransactionSpec}) to return a list of TS for transactionFilter.
But not sure if this is the correct way.

A transaction instance conforms to the transaction spec interface. But what you’re trying to do iterating over the changes and converting those to transaction specs, I do not understand. The way filters work is that you can either just return the original transaction, or that transaction + some additional transaction specs, or a completely new set of transactions.

oh. I need to look at the change to know if it is a new line character to make decision to filter it out or not. I thought i would have to look at transaction.changes one by one to do that. Any advice?

The easiest approach would be to check the fifth argument to the callback in iterChanges to see if .lines > 1 — then it contains a newline — and set a boolean variable from the callback which then determines whether you return the original transaction or block it by returning [].

1 Like