Skip to content

Commit

Permalink
Added new feature for line numbers and bumped major version
Browse files Browse the repository at this point in the history
  • Loading branch information
calumk committed Jan 28, 2024
1 parent 6095607 commit 7422345
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 4 deletions.
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,21 @@
## Why?
CodeFlask was a brilliant project, but seems to be unmaintained, and it required some significant updates to work with a new project I am working on.

### Kitchen Sink Example

```js
cup = new codecup('#cf_holder', {
language: "javascript",
lineNumbers: true ,
copyButton: true,
maxLines : 15,
minLines : 5
});
```


### Changes
* Added max line number option
* Switched from rollup to webpack
* Added example folder
* disabled e2e tests
Expand Down Expand Up @@ -126,6 +140,27 @@ cup.toggleLineNumbers();

```

### Setting max and min lines

```js
> [!IMPORTANT]
> As of `1.90`, You can also set the max line number, (Default is 100), And the min line number, (Default is 1)

> [!NOTE]
> If you want it to be a fixed number of lines, set both to the same number.

```js
import codecup from 'codecup';
const cup = new codecup('#my-selector', {
language: 'js',
lineNumbers: true,
maxLines: 10,
minLines: 10
});
```


### Enabling read only mode

```js
Expand Down
2 changes: 1 addition & 1 deletion dist/codecup.bundle.js

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@
cup = new codecup('#cf_holder', {
language: current_language,
lineNumbers: true ,
copyButton: true
copyButton: true,
maxLines : 15,
minLines : 5
});
demo_init();
}
Expand Down Expand Up @@ -95,7 +97,7 @@
}

#cf_holder{
height:200px;

overflow: hidden;
border : 1px solid #EAEEFB;
border-radius: 4px;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@calumk/codecup",
"version": "1.8.1",
"version": "1.9.0",
"description": "A micro code-editor for awesome web pages",
"main": "dist/codecup.bundle.js",
"files": [
Expand Down
15 changes: 15 additions & 0 deletions src/codecup.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ export default class codecup {
this.opts.ariaLabelledby = this.opts.ariaLabelledby || null
this.opts.readonly = this.opts.readonly || false
this.opts.copyButton = this.opts.copyButton || false
this.opts.maxLines = this.opts.maxLines || 100
this.opts.minLines = this.opts.minLines || 1

// this.opts.handleSelfClosingCharacters = this.opts.handleSelfClosingCharacters || false

Expand Down Expand Up @@ -199,6 +201,19 @@ export default class codecup {
}

this.elLineNumbers.innerHTML = numberList

console.log(this.opts)

// limit the number of lines between max and min line numbers.
let maxLineNumber = this.opts.maxLines
let minLineNumber = this.opts.minLines
let limitedLineNumber = this.lineNumber
if (limitedLineNumber > maxLineNumber) {
limitedLineNumber = maxLineNumber
} else if (limitedLineNumber < minLineNumber) {
limitedLineNumber = minLineNumber
}
this.elWrapper.style.height = (limitedLineNumber*20) + 20 + 'px'
}

listenTextarea () {
Expand Down

0 comments on commit 7422345

Please sign in to comment.