mirror of
https://github.com/flynx/object.js.git
synced 2025-10-29 02:20:08 +00:00
tweaking...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
a22d408ea8
commit
1f1df751c0
16
object.js
16
object.js
@ -93,6 +93,11 @@ function(text, tab_size, leading_tabs){
|
||||
// trim the tail and remove leading blank lines...
|
||||
var lines = text.trimEnd().split(/\n/)
|
||||
while(lines[0].trim() == ''){
|
||||
// XXX we have two options here:
|
||||
// - indent everyline including the first non-blank
|
||||
// - do not indent anything (current)
|
||||
// ...not sure which is best...
|
||||
leading_tabs = 0
|
||||
lines.shift() }
|
||||
// count common indent...
|
||||
var l = lines
|
||||
@ -101,17 +106,20 @@ function(text, tab_size, leading_tabs){
|
||||
return e.trim().length == 0
|
||||
// ignore 0 indent of first line...
|
||||
|| (i == 0 && indent == 0) ?
|
||||
l || indent
|
||||
l
|
||||
// last line -- ignore leading_tabs if lower indent...
|
||||
// XXX BUG this does messes things up for 2 liners...
|
||||
// XXX does not work correctly when:
|
||||
// - two lines
|
||||
// - l is 0
|
||||
// - non-zero leading_tabs...
|
||||
: i == lines.length-1
|
||||
&& indent >= l ?
|
||||
Math.max(indent - leading_tabs, 0)
|
||||
Math.min(l, Math.max(indent - leading_tabs, 0))
|
||||
// initial state...
|
||||
: l < 0 ?
|
||||
indent
|
||||
// min...
|
||||
: Math.min(l, indent) }, -1)
|
||||
: Math.min(l, indent) }, -1) || 0
|
||||
// normalize...
|
||||
return lines
|
||||
.map(function(line, i){
|
||||
|
||||
29
test.js
29
test.js
@ -673,13 +673,30 @@ var cases = test.Cases({
|
||||
},
|
||||
|
||||
text_cases: [
|
||||
// sanity checks...
|
||||
{ input: 'abc',
|
||||
all: 'abc'},
|
||||
{ input: '\n\t\tabc',
|
||||
all: 'abc'},
|
||||
|
||||
// NOTE: there is no way to know what is the indent of 'a'
|
||||
// relative to the rest of the text...
|
||||
// ...without reading the source file, and that should
|
||||
// be avoided.
|
||||
{ input: `a
|
||||
c`,
|
||||
text: 'a\nc',
|
||||
// XXX fail...
|
||||
doc: 'a\n c'},
|
||||
{ input: `a\nc`,
|
||||
text: 'a\nc',
|
||||
doc: 'a\nc'},
|
||||
{ input: `\
|
||||
a
|
||||
c`,
|
||||
all: 'a\n c'},
|
||||
{ input: `
|
||||
a
|
||||
c`,
|
||||
text: 'a\n c',
|
||||
doc: 'a\n c'},
|
||||
{ input: `a
|
||||
b
|
||||
@ -688,13 +705,10 @@ var cases = test.Cases({
|
||||
doc: 'a\n b\n c' },
|
||||
|
||||
|
||||
// XXX text(..): c is not indented...
|
||||
{ input: `
|
||||
a
|
||||
c`,
|
||||
all: 'a\n c' },
|
||||
// XXX text(..): losing all lines but 0 and -1...
|
||||
// XXX text(..): c is not indented...
|
||||
{ input: `
|
||||
a
|
||||
b
|
||||
@ -710,6 +724,11 @@ var cases = test.Cases({
|
||||
b
|
||||
c`,
|
||||
all: `a\n b\nc` },
|
||||
{ input: `
|
||||
a
|
||||
b
|
||||
c`,
|
||||
all: `a\n b\nc` },
|
||||
],
|
||||
text: function(assert){
|
||||
this.text_cases
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user